Class: PatientHttp::Sidekiq::TaskHandler
- Inherits:
-
TaskHandler
- Object
- TaskHandler
- PatientHttp::Sidekiq::TaskHandler
- Defined in:
- lib/patient_http/sidekiq/task_handler.rb
Overview
Sidekiq implementation of TaskHandler.
Handles task lifecycle operations using Sidekiq for job management:
-
Completion and error callbacks are triggered via CallbackWorker
-
Large payloads are stored via ExternalStorage before enqueuing
-
Job retry uses Sidekiq::Client.push
Instance Attribute Summary collapse
-
#sidekiq_job ⇒ Hash
readonly
The Sidekiq job hash containing class, jid, args, etc.
Instance Method Summary collapse
-
#initialize(sidekiq_job) ⇒ TaskHandler
constructor
A new instance of TaskHandler.
-
#job_id ⇒ String
Return the job ID from the Sidekiq job.
-
#on_complete(response, callback) ⇒ void
Trigger the completion callback with the response.
-
#on_error(error, callback) ⇒ void
Trigger the error callback with the error.
-
#retry ⇒ String
Re-enqueue the original Sidekiq job for retry.
-
#worker_class ⇒ Class
Return the worker class from the Sidekiq job.
Constructor Details
#initialize(sidekiq_job) ⇒ TaskHandler
Returns a new instance of TaskHandler.
17 18 19 |
# File 'lib/patient_http/sidekiq/task_handler.rb', line 17 def initialize(sidekiq_job) @sidekiq_job = sidekiq_job end |
Instance Attribute Details
#sidekiq_job ⇒ Hash (readonly)
Returns The Sidekiq job hash containing class, jid, args, etc. Exposed for TaskMonitor crash recovery serialization.
14 15 16 |
# File 'lib/patient_http/sidekiq/task_handler.rb', line 14 def sidekiq_job @sidekiq_job end |
Instance Method Details
#job_id ⇒ String
Return the job ID from the Sidekiq job.
57 58 59 |
# File 'lib/patient_http/sidekiq/task_handler.rb', line 57 def job_id @sidekiq_job["jid"] end |
#on_complete(response, callback) ⇒ void
This method returns an undefined value.
Trigger the completion callback with the response.
Stores the response via ExternalStorage (for large payloads) and enqueues a CallbackWorker to invoke the callback asynchronously.
29 30 31 32 |
# File 'lib/patient_http/sidekiq/task_handler.rb', line 29 def on_complete(response, callback) data = store_if_needed(response.as_json) CallbackWorker.perform_async(data, "response", callback) end |
#on_error(error, callback) ⇒ void
This method returns an undefined value.
Trigger the error callback with the error.
Stores the error via ExternalStorage (for large payloads) and enqueues a CallbackWorker to invoke the callback asynchronously.
42 43 44 45 |
# File 'lib/patient_http/sidekiq/task_handler.rb', line 42 def on_error(error, callback) data = store_if_needed(error.as_json) CallbackWorker.perform_async(data, "error", callback) end |
#retry ⇒ String
Re-enqueue the original Sidekiq job for retry.
50 51 52 |
# File 'lib/patient_http/sidekiq/task_handler.rb', line 50 def retry ::Sidekiq::Client.push(@sidekiq_job) end |
#worker_class ⇒ Class
Return the worker class from the Sidekiq job.
64 65 66 |
# File 'lib/patient_http/sidekiq/task_handler.rb', line 64 def worker_class PatientHttp::ClassHelper.resolve_class_name(@sidekiq_job["class"]) end |