diff options
author | wvengen <dev-rails@willem.engen.nl> | 2015-03-18 10:48:26 +0100 |
---|---|---|
committer | wvengen <dev-rails@willem.engen.nl> | 2015-09-17 22:17:39 +0200 |
commit | 7059ab35f797c163cd8907abcd7d0830b31e56f7 (patch) | |
tree | 708ccbf2da4412030b305f79c629a6961eb487c1 /activejob/lib/active_job/core.rb | |
parent | 61f9e47feac75a2cf4ed9e092bac036294564168 (diff) | |
download | rails-7059ab35f797c163cd8907abcd7d0830b31e56f7.tar.gz rails-7059ab35f797c163cd8907abcd7d0830b31e56f7.tar.bz2 rails-7059ab35f797c163cd8907abcd7d0830b31e56f7.zip |
Add job priorities to ActiveJob
Diffstat (limited to 'activejob/lib/active_job/core.rb')
-rw-r--r-- | activejob/lib/active_job/core.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb index eac7279309..19b900a285 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -18,6 +18,9 @@ module ActiveJob # Queue in which the job will reside. attr_writer :queue_name + # Priority that the job will have (lower is more priority). + attr_writer :priority + # ID optionally provided by adapter attr_accessor :provider_job_id @@ -43,6 +46,7 @@ module ActiveJob # * <tt>:wait</tt> - Enqueues the job with the specified delay # * <tt>:wait_until</tt> - Enqueues the job at the time specified # * <tt>:queue</tt> - Enqueues the job on the specified queue + # * <tt>:priority</tt> - Enqueues the job with the specified priority # # ==== Examples # @@ -51,6 +55,7 @@ module ActiveJob # VideoJob.set(wait_until: Time.now.tomorrow).perform_later(Video.last) # VideoJob.set(queue: :some_queue, wait: 5.minutes).perform_later(Video.last) # VideoJob.set(queue: :some_queue, wait_until: Time.now.tomorrow).perform_later(Video.last) + # VideoJob.set(queue: :some_queue, wait: 5.minutes, priority: 10).perform_later(Video.last) def set(options={}) ConfiguredJob.new(self, options) end @@ -62,6 +67,7 @@ module ActiveJob @arguments = arguments @job_id = SecureRandom.uuid @queue_name = self.class.queue_name + @priority = self.class.priority end # Returns a hash with the job data that can safely be passed to the @@ -71,6 +77,7 @@ module ActiveJob 'job_class' => self.class.name, 'job_id' => job_id, 'queue_name' => queue_name, + 'priority' => priority, 'arguments' => serialize_arguments(arguments), 'locale' => I18n.locale } @@ -99,6 +106,7 @@ module ActiveJob def deserialize(job_data) self.job_id = job_data['job_id'] self.queue_name = job_data['queue_name'] + self.priority = job_data['priority'] self.serialized_arguments = job_data['arguments'] self.locale = job_data['locale'] || I18n.locale end |