Class: ActiveJob::Temporal::WorkflowEnqueuer
- Inherits:
-
Object
- Object
- ActiveJob::Temporal::WorkflowEnqueuer
- Includes:
- WorkflowEnqueuerBatch
- Defined in:
- lib/activejob/temporal/workflow_enqueuer.rb
Overview
Service object for enqueueing jobs as Temporal workflows.
This class handles the mechanics of converting an ActiveJob into a Temporal workflow execution, including payload serialization, workflow ID generation, and options building.
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#enqueue(job, scheduled_at: nil) ⇒ Object
Enqueue a job as a Temporal workflow.
-
#initialize(client, config, logger = nil, workflow_id_builder: nil, payload_builder: nil) ⇒ WorkflowEnqueuer
constructor
A new instance of WorkflowEnqueuer.
Methods included from WorkflowEnqueuerBatch
Constructor Details
#initialize(client, config, logger = nil, workflow_id_builder: nil, payload_builder: nil) ⇒ WorkflowEnqueuer
Returns a new instance of WorkflowEnqueuer.
35 36 37 38 39 40 41 42 |
# File 'lib/activejob/temporal/workflow_enqueuer.rb', line 35 def initialize(client, config, logger = nil, workflow_id_builder: nil, payload_builder: nil) @client_provider = client if client.respond_to?(:call) @client = client unless @client_provider @config = config @logger = logger || config.logger @workflow_id_builder = workflow_id_builder || WorkflowIdBuilder.new(configured_workflow_id_generator) @payload_builder = payload_builder || JobPayloadBuilder.new(config) end |
Instance Method Details
#enqueue(job, scheduled_at: nil) ⇒ Object
Enqueue a job as a Temporal workflow.
Performs validation, builds the payload, generates a workflow ID, constructs workflow options, and starts the workflow via the Temporal client.
66 67 68 69 70 71 72 |
# File 'lib/activejob/temporal/workflow_enqueuer.rb', line 66 def enqueue(job, scheduled_at: nil) validate_job_for_enqueueing(job) scheduled_at = validate_scheduled_at!(scheduled_at) workflow_id = @workflow_id_builder.build(job) payload = build_payload(job, workflow_id: workflow_id, scheduled_at: scheduled_at) enqueue_with_payload(job, payload, workflow_id) end |