Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/gush/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,27 @@ def resolve_dependencies
end
end

def find_job(name)
match_data = /(?<klass>\w*[^-])-(?<identifier>.*)/.match(name.to_s)
def build_job_lookup
@job_lookup = {
klass: jobs.each_with_object({}) { |job, lookup| lookup[job.klass.to_s] = job },
name: jobs.each_with_object({}) { |job, lookup| lookup[job.name.to_s] = job }
}
end

def find_job(identifier)
# Build the lookup table if it doesn't exist
build_job_lookup unless @job_lookup

# Use regex to determine which lookup to use
match_data = /(?<klass>\w*[^-])-(?<identifier>.*)/.match(identifier.to_s)

if match_data.nil?
job = jobs.find { |node| node.klass.to_s == name.to_s }
# Lookup by klass if the pattern doesn't match
@job_lookup[:klass][identifier.to_s]
else
job = jobs.find { |node| node.name.to_s == name.to_s }
# Lookup by name if the pattern matches
@job_lookup[:name][identifier.to_s]
end

job
end

def finished?
Expand Down Expand Up @@ -146,6 +157,7 @@ def reload

self.jobs = flow.jobs
self.stopped = flow.stopped
@job_lookup = nil

self
end
Expand Down