Class: Workhorse::Performer

Inherits:
Object
  • Object
show all
Defined in:
lib/workhorse/performer.rb

Overview

Executes individual jobs within worker processes. The Performer handles job lifecycle management, error handling, and integration with Rails application executors.

Examples:

Basic usage (typically called internally)

performer = Workhorse::Performer.new(job_id, worker)
performer.perform

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_job_id, worker) ⇒ Performer

Creates a new performer for a specific job.



17
18
19
20
21
# File 'lib/workhorse/performer.rb', line 17

def initialize(db_job_id, worker)
  @db_job = Workhorse::DbJob.find(db_job_id)
  @worker = worker
  @started = false
end

Instance Attribute Details

#workerWorkhorse::Worker (readonly)



11
12
13
# File 'lib/workhorse/performer.rb', line 11

def worker
  @worker
end

Instance Method Details

#performvoid

This method returns an undefined value.

Executes the job with full error handling and state management. This method can only be called once per performer instance.

Raises:

  • (RuntimeError)

    If called more than once



28
29
30
31
32
33
34
35
36
# File 'lib/workhorse/performer.rb', line 28

def perform
  begin # rubocop:disable Style/RedundantBegin
    fail 'Performer can only run once.' if @started
    @started = true
    perform!
  rescue Exception => e
    Workhorse.on_exception.call(e)
  end
end