Module: Leveret::Job::ClassMethods
- Defined in:
- lib/leveret/job.rb
Overview
Class methods to mixin with your job
Instance Method Summary collapse
-
#enqueue(params = {}) ⇒ Object
Place a job onto the queue for processing by a worker.
-
#job_options ⇒ Hash
The current set of options for this job, the
queue_name
andpriority
. -
#perform(params = Parameters.new) ⇒ Symbol
Shorthand to intialize a new job and run it with error handling.
-
#priority(priority) ⇒ Object
Set a custom priority for this job.
-
#queue(q_name = nil) ⇒ Queue
Cached Queue object for publishing jobs.
-
#queue_name(name) ⇒ Object
Set a custom queue for this job.
Instance Method Details
#enqueue(params = {}) ⇒ Object
Place a job onto the queue for processing by a worker.
136 137 138 139 140 141 142 143 144 |
# File 'lib/leveret/job.rb', line 136 def enqueue(params = {}) priority = params.delete(:priority) || [:priority] q_name = params.delete(:queue_name) || [:queue_name] Leveret.log.info "Queuing #{name} to #{q_name} (#{priority}) with #{params}" payload = { job: self.name, params: params } queue(q_name).publish(payload, priority: priority) end |
#job_options ⇒ Hash
Returns The current set of options for this job, the queue_name
and priority
.
121 122 123 124 125 126 |
# File 'lib/leveret/job.rb', line 121 def @job_options ||= { queue_name: Leveret.configuration.default_queue_name, priority: :normal } end |
#perform(params = Parameters.new) ⇒ Symbol
Shorthand to intialize a new job and run it with error handling
102 103 104 |
# File 'lib/leveret/job.rb', line 102 def perform(params = Parameters.new) new(params).run end |
#priority(priority) ⇒ Object
Set a custom priority for this job
116 117 118 |
# File 'lib/leveret/job.rb', line 116 def priority(priority) [:priority] = priority end |
#queue(q_name = nil) ⇒ Queue
Returns Cached Queue object for publishing jobs.
151 152 153 154 155 |
# File 'lib/leveret/job.rb', line 151 def queue(q_name = nil) q_name ||= [:queue_name] @queue ||= {} @queue[q_name] ||= Leveret::Queue.new(q_name) end |
#queue_name(name) ⇒ Object
Set a custom queue for this job
109 110 111 |
# File 'lib/leveret/job.rb', line 109 def queue_name(name) [:queue_name] = name end |