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_nameandpriority. -
#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.
132 133 134 135 136 137 138 139 140 |
# File 'lib/leveret/job.rb', line 132 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.
117 118 119 120 121 122 |
# File 'lib/leveret/job.rb', line 117 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
98 99 100 |
# File 'lib/leveret/job.rb', line 98 def perform(params = Parameters.new) new(params).run end |
#priority(priority) ⇒ Object
Set a custom priority for this job
112 113 114 |
# File 'lib/leveret/job.rb', line 112 def priority(priority) [:priority] = priority end |
#queue(q_name = nil) ⇒ Queue
Returns Cached Queue object for publishing jobs.
147 148 149 150 151 |
# File 'lib/leveret/job.rb', line 147 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
105 106 107 |
# File 'lib/leveret/job.rb', line 105 def queue_name(name) [:queue_name] = name end |