Class: PatientHttp::Sidekiq::TaskHandler

Inherits:
TaskHandler
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(sidekiq_job) ⇒ TaskHandler

Returns a new instance of TaskHandler.

Parameters:

  • sidekiq_job (Hash)

    The Sidekiq job hash with “class”, “jid”, “args”, etc.



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_jobHash (readonly)

Returns The Sidekiq job hash containing class, jid, args, etc. Exposed for TaskMonitor crash recovery serialization.

Returns:

  • (Hash)

    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_idString

Return the job ID from the Sidekiq job.

Returns:

  • (String)

    job ID



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.

Parameters:

  • response (Response)

    the HTTP response object

  • callback (String)

    callback class name



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.

Parameters:

  • error (Error)

    the error object

  • callback (String)

    callback class name



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

#retryString

Re-enqueue the original Sidekiq job for retry.

Returns:

  • (String)

    the job ID



50
51
52
# File 'lib/patient_http/sidekiq/task_handler.rb', line 50

def retry
  ::Sidekiq::Client.push(@sidekiq_job)
end

#worker_classClass

Return the worker class from the Sidekiq job.

Returns:

  • (Class)

    worker class



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