Class: Kiqchestra::BaseJob
- Inherits:
-
Object
- Object
- Kiqchestra::BaseJob
- Includes:
- Sidekiq::Worker
- Defined in:
- lib/kiqchestra/base_job.rb
Overview
BaseJob provides a standard interface for all workflow jobs. It includes the necessary callback mechanism to notify the Workflow once a job has completed and trigger any follow-up jobs based on the dependencies.
Subclasses are expected to implement the perform method to define
the specific logic for the job. This method will be automatically
invoked as part of the job execution flow, and callbacks like on_complete
will be triggered when the job finishes.
Instance Method Summary collapse
-
#perform(workflow_id, *args) ⇒ Object
Perform the job and trigger workflow callbacks on completion.
-
#perform_job(*args) ⇒ Object
Subclasses should define the actual job logic here.
Instance Method Details
#perform(workflow_id, *args) ⇒ Object
Perform the job and trigger workflow callbacks on completion.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kiqchestra/base_job.rb', line 22 def perform(workflow_id, *args) @workflow_id = workflow_id @args = args log_info "Starting job #{job_name} in workflow #{@workflow_id} with args: #{@args.inspect}" begin # Delegate the actual job work to the subclass's perform method perform_job(*@args) workflow.handle_completed_job job_name rescue StandardError => e log_error "#{job_name} failed: #{e.}" # Re-raise to let Sidekiq handle retries raise e end end |
#perform_job(*args) ⇒ Object
Subclasses should define the actual job logic here.
This is called by the perform method of BaseJob.
45 46 47 |
# File 'lib/kiqchestra/base_job.rb', line 45 def perform_job(*args) raise NotImplementedError, "Subclasses must implement `perform_job`" end |