class Gush::Job

Attributes

enqueued_at[RW]
failed_at[RW]
finished_at[RW]
incoming[RW]
klass[RW]
name[R]
outgoing[RW]
output_payload[R]
params[RW]
payloads[R]
payloads_hash[RW]
started_at[RW]
workflow_id[RW]

Public Class Methods

from_hash(flow, hash) click to toggle source
# File lib/gush/job.rb, line 32
def self.from_hash(flow, hash)
  hash[:klass].constantize.new(flow, hash)
end
new(workflow, opts = {}) click to toggle source
# File lib/gush/job.rb, line 7
def initialize(workflow, opts = {})
  @workflow = workflow
  options = opts.dup
  assign_variables(options)
end

Public Instance Methods

as_json() click to toggle source
# File lib/gush/job.rb, line 13
def as_json
  {
    name: name,
    klass: self.class.to_s,
    incoming: incoming,
    outgoing: outgoing,
    finished_at: finished_at,
    enqueued_at: enqueued_at,
    started_at: started_at,
    failed_at: failed_at,
    params: params,
    output_payload: output_payload
  }
end
enqueue!() click to toggle source
# File lib/gush/job.rb, line 53
def enqueue!
  @enqueued_at = current_timestamp
  @started_at = nil
  @finished_at = nil
  @failed_at = nil
end
enqueued?() click to toggle source
# File lib/gush/job.rb, line 68
def enqueued?
  !enqueued_at.nil?
end
fail!() click to toggle source
# File lib/gush/job.rb, line 64
def fail!
  @finished_at = @failed_at = current_timestamp
end
failed?() click to toggle source
# File lib/gush/job.rb, line 76
def failed?
  !failed_at.nil?
end
finish!() click to toggle source
# File lib/gush/job.rb, line 60
def finish!
  @finished_at = current_timestamp
end
finished?() click to toggle source
# File lib/gush/job.rb, line 72
def finished?
  !finished_at.nil?
end
has_no_dependencies?() click to toggle source
# File lib/gush/job.rb, line 102
def has_no_dependencies?
  incoming.empty?
end
output(data) click to toggle source
# File lib/gush/job.rb, line 36
def output(data)
  @output_payload = data
end
parents_succeeded?() click to toggle source
# File lib/gush/job.rb, line 96
def parents_succeeded?
  incoming.all? do |name|
    @workflow.find_job(name).succeeded?
  end
end
ready_to_start?() click to toggle source
# File lib/gush/job.rb, line 92
def ready_to_start?
  !running? && !enqueued? && !finished? && !failed? && parents_succeeded?
end
running?() click to toggle source
# File lib/gush/job.rb, line 88
def running?
  started? && !finished?
end
start!() click to toggle source
# File lib/gush/job.rb, line 49
def start!
  @started_at = current_timestamp
end
started?() click to toggle source
# File lib/gush/job.rb, line 84
def started?
  !started_at.nil?
end
succeeded?() click to toggle source
# File lib/gush/job.rb, line 80
def succeeded?
  finished? && !failed?
end
to_json(options = {}) click to toggle source
# File lib/gush/job.rb, line 28
def to_json(options = {})
  Gush::JSON.encode(as_json)
end
work() click to toggle source
# File lib/gush/job.rb, line 46
def work
end

Private Instance Methods

assign_variables(opts) click to toggle source
# File lib/gush/job.rb, line 115
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] || {}
  @klass          = opts[:klass]
  @output_payload = opts[:output_payload]
end
current_timestamp() click to toggle source
# File lib/gush/job.rb, line 111
def current_timestamp
  Time.now.to_i
end
logger() click to toggle source
# File lib/gush/job.rb, line 107
def logger
  Sidekiq.logger
end