From cab5be04410528ba5edf65e9c3ba86cc4f1fcebc Mon Sep 17 00:00:00 2001 From: David Bailey Date: Fri, 14 Apr 2023 10:16:57 +0200 Subject: [PATCH] feat: :sparkles: break out the artefact wait functionality --- lib/comfpile/artefact.rb | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/comfpile/artefact.rb b/lib/comfpile/artefact.rb index 85727ff..4b7bc8e 100644 --- a/lib/comfpile/artefact.rb +++ b/lib/comfpile/artefact.rb @@ -154,20 +154,44 @@ module Comfpile def reference_artefact(stage, target, required: false) artefact = craft_artefact(stage, target) - if(artefact.nil? and required) - fail! "Missing artefact dependency for #{stage} #{target}!" - elsif(required) - @waitlist << { - artefact: artefact, - required: true - } - end + wait_on(artefact) if required @referenced_artefacts << artefact artefact end + # + # Wait on a specific artefact to complete + # + # @param [Comfpile::Artefact, nil] artefact The artefact to wait on + # @param [Boolean] required Whether or not this artefact is required. + # When set to true (default), a failed artefact will skip this artefact. + # When set to false, this artefact will ignore the failure. + # + # @return [Boolean] true when we have to wait on this artefact or + # it failed, false if we're all good + def wait_on(artefact, required: true) + if(artefact.nil?) + fail! "Missing artefact dependency for #{stage} #{target}!" if required + + true + elsif artefact.in_progress? + @waitlist << { + artefact: artefact, + required: true + } + + true + elsif(required and not artefact.succeeded?) + skip! "Failed artefact dependency: #{artefact}" + + true + end + + false + end + # Find or create a new artefact # # @param [Symbol] stage The type of item to create.