Module: Conflow::Worker

Defined in:
lib/conflow/worker.rb

Overview

It adds #perform method which accepts two parameters: flow_id and job_id and a block. Block yields Class name and parameters. If block returns without errors, job is considered finished.

Instance Method Summary collapse

Instance Method Details

#perform(flow_id, job_id) {|worker_type, params| ... } ⇒ Object

Returns result of the block execution.

Examples:

Performing job with simple new/call pattern

class FlowWorkerJob
  include Conflow::Worker
  include Sidekiq::Worker

  def perform(flow_id, job_id)
    super do |worker_type, params|
      worker_type.new(params).call
    end
  end
end

Parameters:

  • flow_id (Integer)

    id of the flow

  • job_id (Integer)

    id of the job to be performed

Yield Parameters:

  • worker_type (Class)

    class supplied on job creation

  • params (Hash)

    parameters of the job supplied on creation

Returns:

  • (Object)

    result of the block execution



25
26
27
28
29
30
31
32
# File 'lib/conflow/worker.rb', line 25

def perform(flow_id, job_id)
  job = Conflow::Job.new(job_id)
  flow = Conflow::Flow.find(flow_id)

  flow.start(job)

  yield(job.worker_type, job.params).tap { |result| flow.finish(job, result) }
end