class Workflow::Join::Sidekiq::Job

Constants

DONE

attr_accessor :worker, :args, :result, :fails

TABLE_NAME

Public Class Methods

lookup!(host, worker) click to toggle source
# File lib/workflow/join/sidekiq/job.rb, line 40
def lookup!(host, worker)
  params = { host: host.class.to_s, host_id: host.id, worker: worker.to_s }
  where(**params).last || create!(**params)
end
migration(table_name = TABLE_NAME) click to toggle source
# File lib/workflow/join/sidekiq/job.rb, line 12
          def migration(table_name = TABLE_NAME)
            <<-MIGRATION
            class CreateWorkflowJobs < ::ActiveRecord::Migration
              def change
                create_table :#{table_name} do |t|
                  t.string   :workflow_state, default: 'scheduled', null: false

                  t.string   :host
                  t.integer  :host_id
                  t.string   :worker

                  t.text     :args
                  t.text     :result
                  t.text     :fails

                  t.string   :workflow_pending_transitions
                  t.string   :workflow_pending_callbacks

                  t.timestamps
                end

                add_index :#{table_name}, :workflow_state, unique: false
                add_index :#{table_name}, [:host, :host_id, :worker], unique: true
              end
            end
            MIGRATION
          end
worker(worker) click to toggle source
# File lib/workflow/join/sidekiq/job.rb, line 45
def worker(worker)
  case worker
  when String, Symbol then Kernel.const_get(worker)
  when Module then worker
  else fail ArgumentError, "Workflow::Join::Sidekiq::Job#worker expects a string/class as an argument, got #{worker.inspect}."
  end
end

Public Instance Methods

on_failed_entry(_old_state, _event, *args) click to toggle source
# File lib/workflow/join/sidekiq/job.rb, line 78
def on_failed_entry(_old_state, _event, *args)
  timestamp = Time.respond_to?(:zone) && Time.zone ? Time.zone.now : Time.now
  (self.fails ||= {})[timestamp] = args
end
on_running_entry(_old_state, _event, *args) click to toggle source
# File lib/workflow/join/sidekiq/job.rb, line 74
def on_running_entry(_old_state, _event, *args)
  Job::Worker.perform_async(*args, ★: id) # FIXME: Anything more elegant?
end
to_hash() click to toggle source
# File lib/workflow/join/sidekiq/job.rb, line 89
def to_hash
  {
    # id: id,
    host: host,
    host_id: host_id,
    worker: worker,
    args: args,
    result: result,
    errors: fails,
    workflow_state: workflow_state,
    state: workflow_state.to_sym
  }
end