class Rworkflow::Worker

Disable pushing back indefinitely

Public Class Methods

generate_lifecycle(&block) click to toggle source
# File lib/rworkflow/worker.rb, line 44
def generate_lifecycle(&block)
  return Rworkflow::Lifecycle.new do |lc|
    lc.state(self.class.name, worker: self.class, &block)
    lc.initial = self.class.name
  end
end
load_workflow(id) click to toggle source
# File lib/rworkflow/worker.rb, line 51
def load_workflow(id)
  workflow = Flow.load(id)
  return workflow if !workflow.nil? && workflow.valid?

  Rails.logger.warn("Worker #{self.name} tried to load non existent workflow #{id}")
  return nil
end
new(*args) click to toggle source
Calls superclass method
# File lib/rworkflow/minitest/worker.rb, line 4
def initialize(*args)
  super
  @__pushed_back = []
end

Public Instance Methods

perform(id, state_name) click to toggle source
# File lib/rworkflow/worker.rb, line 8
def perform(id, state_name)
  @workflow = self.class.load_workflow(id)
  @state_name = state_name
  if !@workflow.nil?
    if !@workflow.paused?
      @workflow.fetch(self.jid, state_name) do |objects|
        if objects.present?
          Rails.logger.debug("Starting #{self.class}::process() (flow #{id})")
          process(objects)
          Rails.logger.debug("Finished #{self.class}::process() (flow #{id})")
        else
          Rails.logger.debug("No objects to process for #{self.class}")
        end
      end
    end
  end
rescue Exception => e
  Rails.logger.error("Exception produced on #{@state_name} for flow #{id} on perform: #{e.message}\n#{e.backtrace}")
  raise e
end
process(_objects) click to toggle source
# File lib/rworkflow/worker.rb, line 39
def process(_objects)
  raise NotImplementedError
end
push_back(objects) click to toggle source
# File lib/rworkflow/minitest/worker.rb, line 13
def push_back(objects)
  @__pushed_back.concat(objects)
end
pushed_back() click to toggle source
# File lib/rworkflow/minitest/worker.rb, line 9
def pushed_back
  return @__pushed_back
end
transition(to_state, objects) click to toggle source
# File lib/rworkflow/worker.rb, line 29
def transition(to_state, objects)
  @workflow.transition(@state_name, to_state, objects)
  Rails.logger.debug("State #{@state_name} transitioned #{Array.wrap(objects).size} objects to state #{to_state} (flow #{@workflow.id})")
end