Class: Workhorse::Performer
- Inherits:
-
Object
- Object
- Workhorse::Performer
- 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.
Instance Attribute Summary collapse
-
#worker ⇒ Workhorse::Worker
readonly
The worker that owns this performer.
Instance Method Summary collapse
-
#initialize(db_job_id, worker) ⇒ Performer
constructor
Creates a new performer for a specific job.
-
#perform ⇒ void
Executes the job with full error handling and state management.
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
#worker ⇒ Workhorse::Worker (readonly)
11 12 13 |
# File 'lib/workhorse/performer.rb', line 11 def worker @worker end |
Instance Method Details
#perform ⇒ void
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.
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 |