Class: Shoryuken::WorkerRegistry Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/shoryuken/worker_registry.rb

Overview

This class is abstract.

Subclass and implement all methods to create a custom registry

Abstract base class for worker registries. Defines the interface for storing and retrieving worker classes.

Direct Known Subclasses

DefaultWorkerRegistry

Instance Method Summary collapse

Instance Method Details

#batch_receive_messages?(_queue) ⇒ Boolean

Checks if the workers for a queue support batch message processing

Parameters:

  • _queue (String)

    the queue name

Returns:

  • (Boolean)

    true if batch processing is supported

Raises:

  • (NotImplementedError)

    if not implemented by subclass



13
14
15
16
# File 'lib/shoryuken/worker_registry.rb', line 13

def batch_receive_messages?(_queue)
  # true if the workers for queue support batch processing of messages
  fail NotImplementedError
end

#clearvoid

This method returns an undefined value.

Removes all worker registrations

Raises:

  • (NotImplementedError)

    if not implemented by subclass



22
23
24
25
# File 'lib/shoryuken/worker_registry.rb', line 22

def clear
  # must remove all worker registrations
  fail NotImplementedError
end

#fetch_worker(_queue, _message) ⇒ Object

Fetches a worker instance for processing a message

Parameters:

Returns:

  • (Object)

    a worker instance

Raises:

  • (NotImplementedError)

    if not implemented by subclass



33
34
35
36
37
# File 'lib/shoryuken/worker_registry.rb', line 33

def fetch_worker(_queue, _message)
  # must return an instance of the worker that handles
  # message received on queue
  fail NotImplementedError
end

#queuesArray<String>

Returns a list of all queues with registered workers

Returns:

  • (Array<String>)

    the queue names

Raises:

  • (NotImplementedError)

    if not implemented by subclass



43
44
45
46
# File 'lib/shoryuken/worker_registry.rb', line 43

def queues
  # must return a list of all queues with registered workers
  fail NotImplementedError
end

#register_worker(_queue, _clazz) ⇒ void

This method returns an undefined value.

Registers a worker class for a queue

Parameters:

  • _queue (String)

    the queue name

  • _clazz (Class)

    the worker class

Raises:

  • (NotImplementedError)

    if not implemented by subclass



54
55
56
57
# File 'lib/shoryuken/worker_registry.rb', line 54

def register_worker(_queue, _clazz)
  # must register the worker as a consumer of messages from queue
  fail NotImplementedError
end

#workers(_queue) ⇒ Array<Class>

Returns all worker classes registered for a queue

Parameters:

  • _queue (String)

    the queue name

Returns:

  • (Array<Class>)

    the worker classes, or empty array

Raises:

  • (NotImplementedError)

    if not implemented by subclass



64
65
66
67
# File 'lib/shoryuken/worker_registry.rb', line 64

def workers(_queue)
  # must return the list of workers registered for queue, or []
  fail NotImplementedError
end