lib/gush/workflow.rb in gush-0.3 vs lib/gush/workflow.rb in gush-0.3.1

- old
+ new

@@ -9,10 +9,12 @@ @jobs = [] @dependencies = [] @persisted = false @stopped = false @arguments = args + + setup end def self.find(id) Gush::Client.new.find_workflow(id) end @@ -21,14 +23,21 @@ flow = new(*args) flow.save flow end + def continue + client = Gush::Client.new + failed_jobs = jobs.select(&:failed?) + + failed_jobs.each do |job| + client.enqueue_job(id, job) + end + end + def save - configure(*@arguments) - resolve_dependencies - client.persist_workflow(self) + persist! end def configure(*args) end @@ -61,11 +70,17 @@ from.outgoing << dependency[:to] end end def find_job(name) - jobs.find { |node| node.name == name.to_s || node.class.to_s == name.to_s } + match_data = /(?<klass>\w*[^-])-(?<identifier>.*)/.match(name.to_s) + if match_data.nil? + job = jobs.find { |node| node.class.to_s == name.to_s } + else + job = jobs.find { |node| node.name.to_s == name.to_s } + end + job end def finished? jobs.all?(&:finished?) end @@ -88,25 +103,27 @@ def run(klass, opts = {}) options = node = klass.new(self, { - name: klass.to_s, + name: client.next_free_job_id(id,klass.to_s), params: opts.fetch(:params, {}) }) jobs << node deps_after = [*opts[:after]] deps_after.each do |dep| - @dependencies << {from: dep.to_s, to: klass.to_s } + @dependencies << {from: dep.to_s, to: node.name.to_s } end deps_before = [*opts[:before]] deps_before.each do |dep| - @dependencies << {from: klass.to_s, to: dep.to_s } + @dependencies << {from: node.name.to_s, to: dep.to_s } end + + node.name end def reload self.class.find(id) end @@ -162,13 +179,18 @@ def self.descendants ObjectSpace.each_object(Class).select { |klass| klass < self } end def id - @id ||= client.next_free_id + @id ||= client.next_free_workflow_id end private + + def setup + configure(*@arguments) + resolve_dependencies + end def client @client ||= Client.new end