Class: Rosette::Queuing::Job
- Inherits:
-
Object
- Object
- Rosette::Queuing::Job
- Defined in:
- lib/rosette/queuing/job.rb
Overview
Base class for jobs that can be run on a Rosette queue implementation.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_QUEUE_NAME =
The name of the queue to use when no custom queue name is specified.
'default'- DEFAULT_DELAY =
The default minimum number of seconds to wait before executing each job.
0
Class Method Summary collapse
-
.queue_name ⇒ String
Returns the name of the queue this job will be run in.
-
.set_queue_name(queue_name) ⇒ void
Sets the name of the queue this job will be run in.
Instance Method Summary collapse
-
#delay ⇒ Fixnum
Returns the minimum number of seconds to wait before executing this job.
-
#set_delay(delay) ⇒ void
Sets the amount of time to wait before executing this job.
-
#to_args ⇒ Array<Object>
Gets an array of the arguments to use to re-create this job later.
-
#work(rosette_config, logger) ⇒ void
Performs this job’s task.
Class Method Details
.queue_name ⇒ String
Returns the name of the queue this job will be run in. For implementations that don’t offer named queues, this value should be ignored.
20 21 22 |
# File 'lib/rosette/queuing/job.rb', line 20 def queue_name @queue_name || DEFAULT_QUEUE_NAME end |
.set_queue_name(queue_name) ⇒ void
This method returns an undefined value.
Sets the name of the queue this job will be run in. Implementations that don’t offer named queues shouldn’t need to call this method, although nothing bad will happen if they do.
30 31 32 |
# File 'lib/rosette/queuing/job.rb', line 30 def set_queue_name(queue_name) @queue_name = queue_name end |
Instance Method Details
#delay ⇒ Fixnum
Returns the minimum number of seconds to wait before executing this job.
59 60 61 |
# File 'lib/rosette/queuing/job.rb', line 59 def delay @delay || DEFAULT_DELAY end |
#set_delay(delay) ⇒ void
This method returns an undefined value.
Sets the amount of time to wait before executing this job.
68 69 70 |
# File 'lib/rosette/queuing/job.rb', line 68 def set_delay(delay) @delay = delay end |
#to_args ⇒ Array<Object>
Gets an array of the arguments to use to re-create this job later. Most implementations will expect these arguments to be serializable in some way so they can be stored in a cache or database.
51 52 53 54 |
# File 'lib/rosette/queuing/job.rb', line 51 def to_args raise NotImplementedError, 'expected to be implemented in derived classes' end |
#work(rosette_config, logger) ⇒ void
This method returns an undefined value.
Performs this job’s task.
41 42 43 44 |
# File 'lib/rosette/queuing/job.rb', line 41 def work(rosette_config, logger) raise NotImplementedError, 'expected to be implemented in derived classes' end |