Class: Rosette::Queuing::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/rosette/queuing/job.rb

Overview

Base class for jobs that can be run on a Rosette queue implementation.

Direct Known Subclasses

Commits::CommitJob

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

Instance Method Summary collapse

Class Method Details

.queue_nameString

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.

Returns:

  • (String)

    The name of the queue.


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.

Parameters:

  • queue_name (String)

    The name of the queue to run the job in.


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

#delayFixnum

Returns the minimum number of seconds to wait before executing this job.

Returns:

  • (Fixnum)

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.

Parameters:

  • delay (Fixnum)

    The minimum amount of time in seconds 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_argsArray<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.

Returns:

  • (Array<Object>)

    the list of job arguments.

Raises:

  • (NotImplementedError)

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.

Parameters:

  • rosette_config (Configurator)

    The rosette config to pass to the job when executing.

  • logger (Logger)

    The logger to pass to the job when executing.

Raises:

  • (NotImplementedError)

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