feat: break out the artefact wait functionality

This commit is contained in:
David Bailey 2023-04-14 10:16:57 +02:00
parent 379a016621
commit cab5be0441

View file

@ -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.