lib/gush/job.rb in gush-0.1.1 vs lib/gush/job.rb in gush-0.1.2

- old
+ new

@@ -1,33 +1,29 @@ module Gush class Job + attr_accessor :workflow_id, :incoming, :outgoing, :params, + :finished_at, :failed_at, :started_at, :enqueued_at, :payloads + attr_reader :name, :output_payload, :params - attr_accessor :workflow_id, :incoming, :outgoing, - :finished_at, :failed_at, :started_at, :enqueued_at - - attr_reader :name - def initialize(workflow, opts = {}) @workflow = workflow options = opts.dup assign_variables(options) end def as_json { - name: @name, + name: name, klass: self.class.to_s, - finished: finished?, - enqueued: enqueued?, - failed: failed?, - incoming: @incoming, - outgoing: @outgoing, + incoming: incoming, + outgoing: outgoing, finished_at: finished_at, enqueued_at: enqueued_at, started_at: started_at, failed_at: failed_at, - running: running? + params: params, + output_payload: output_payload } end def to_json(options = {}) Gush::JSON.encode(as_json) @@ -35,10 +31,14 @@ def self.from_hash(flow, hash) hash[:klass].constantize.new(flow, hash) end + def output(data) + @output_payload = data + end + def work end def start! @started_at = current_timestamp @@ -54,12 +54,11 @@ def finish! @finished_at = current_timestamp end def fail! - @finished_at = current_timestamp - @failed_at = current_timestamp + @finished_at = @failed_at = current_timestamp end def enqueued? !!enqueued_at end @@ -87,21 +86,22 @@ def has_no_dependencies? incoming.empty? end private - def current_timestamp Time.now.to_i end - def assign_variables(options) - @name = options[:name] - @incoming = options[:incoming] || [] - @outgoing = options[:outgoing] || [] - @failed_at = options[:failed_at] - @finished_at = options[:finished_at] - @started_at = options[:started_at] - @enqueued_at = options[:enqueued_at] + def assign_variables(opts) + @name = opts[:name] + @incoming = opts[:incoming] || [] + @outgoing = opts[:outgoing] || [] + @failed_at = opts[:failed_at] + @finished_at = opts[:finished_at] + @started_at = opts[:started_at] + @enqueued_at = opts[:enqueued_at] + @params = opts[:params] || {} + @output_payload = opts[:output_payload] end end end