Class: PatientHttp::TaskHandler Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/patient_http/task_handler.rb

Overview

This class is abstract.

Subclass and implement all methods to create a concrete handler.

Abstract base class for handling task lifecycle operations.

TaskHandler abstracts the job system integration, allowing RequestTask to work with any job system without direct dependencies. Implementations handle completion callbacks, error callbacks, and job retry operations.

Examples:

Creating a custom handler

class MyTaskHandler < PatientHttp::TaskHandler
  def on_complete(response, callback)
    # Trigger completion callback
  end

  def on_error(error, callback)
    # Trigger error callback
  end

  def retry
    # Re-enqueue the job
  end
end

Instance Method Summary collapse

Instance Method Details

#on_complete(response, callback) ⇒ void

This method returns an undefined value.

Trigger the completion callback with the response.

Parameters:

  • response (Response)

    the HTTP response object

  • callback (String)

    callback class name

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/patient_http/task_handler.rb', line 32

def on_complete(response, callback)
  raise NotImplementedError, "#{self.class}#on_complete must be implemented"
end

#on_error(error, callback) ⇒ void

This method returns an undefined value.

Trigger the error callback with the error.

Parameters:

  • error (Error)

    the error object

  • callback (String)

    callback class name

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/patient_http/task_handler.rb', line 41

def on_error(error, callback)
  raise NotImplementedError, "#{self.class}#on_error must be implemented"
end

#retryString

Re-enqueue the original job for retry.

Called when a request cannot be completed (e.g., processor shutdown) and needs to be retried later.

Returns:

  • (String)

    the new job ID

Raises:

  • (NotImplementedError)


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

def retry
  raise NotImplementedError, "#{self.class}#retry must be implemented"
end