class Gush::Job

Attributes

enqueued_at[RW]
failed_at[RW]
finished_at[RW]
id[R]
incoming[RW]
klass[RW]
outgoing[RW]
output_payload[R]
params[RW]
payloads[RW]
queue[RW]
started_at[RW]
workflow_id[RW]

Public Class Methods

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

Public Instance Methods

as_json() click to toggle source
# File lib/gush/job.rb, line 12
def as_json
  {
    id: id,
    klass: klass.to_s,
    queue: queue,
    incoming: incoming,
    outgoing: outgoing,
    finished_at: finished_at,
    enqueued_at: enqueued_at,
    started_at: started_at,
    failed_at: failed_at,
    params: params,
    workflow_id: workflow_id,
    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
name() click to toggle source
# File lib/gush/job.rb, line 29
def name
  @name ||= "#{klass}|#{id}"
end
output(data) click to toggle source
# File lib/gush/job.rb, line 41
def output(data)
  @output_payload = data
end
parents_succeeded?() click to toggle source
# File lib/gush/job.rb, line 96
def parents_succeeded?
  !incoming.any? do |name|
    !client.find_job(workflow_id, name).succeeded?
  end
end
perform() click to toggle source
# File lib/gush/job.rb, line 45
def perform
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 48
def start!
  @started_at = current_timestamp
  @failed_at = nil
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 33
def to_json(options = {})
  Gush::JSON.encode(as_json)
end

Private Instance Methods

assign_variables(opts) click to toggle source
# File lib/gush/job.rb, line 116
def assign_variables(opts)
  @id             = opts[:id]
  @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] || self.class
  @output_payload = opts[:output_payload]
  @workflow_id    = opts[:workflow_id]
  @queue          = opts[:queue]
end
client() click to toggle source
# File lib/gush/job.rb, line 108
def client
  @client ||= Client.new
end
current_timestamp() click to toggle source
# File lib/gush/job.rb, line 112
def current_timestamp
  Time.now.to_i
end