@@ -18,6 +18,9 @@ module Core
18
18
# Queue in which the job will reside.
19
19
attr_writer :queue_name
20
20
21
+ # Priority that the job will have (lower is more priority).
22
+ attr_writer :priority
23
+
21
24
# ID optionally provided by adapter
22
25
attr_accessor :provider_job_id
23
26
@@ -43,6 +46,7 @@ def deserialize(job_data)
43
46
# * <tt>:wait</tt> - Enqueues the job with the specified delay
44
47
# * <tt>:wait_until</tt> - Enqueues the job at the time specified
45
48
# * <tt>:queue</tt> - Enqueues the job on the specified queue
49
+ # * <tt>:priority</tt> - Enqueues the job with the specified priority
46
50
#
47
51
# ==== Examples
48
52
#
@@ -51,6 +55,7 @@ def deserialize(job_data)
51
55
# VideoJob.set(wait_until: Time.now.tomorrow).perform_later(Video.last)
52
56
# VideoJob.set(queue: :some_queue, wait: 5.minutes).perform_later(Video.last)
53
57
# VideoJob.set(queue: :some_queue, wait_until: Time.now.tomorrow).perform_later(Video.last)
58
+ # VideoJob.set(queue: :some_queue, wait: 5.minutes, priority: 10).perform_later(Video.last)
54
59
def set ( options = { } )
55
60
ConfiguredJob . new ( self , options )
56
61
end
@@ -62,6 +67,7 @@ def initialize(*arguments)
62
67
@arguments = arguments
63
68
@job_id = SecureRandom . uuid
64
69
@queue_name = self . class . queue_name
70
+ @priority = self . class . priority
65
71
end
66
72
67
73
# Returns a hash with the job data that can safely be passed to the
@@ -71,6 +77,7 @@ def serialize
71
77
'job_class' => self . class . name ,
72
78
'job_id' => job_id ,
73
79
'queue_name' => queue_name ,
80
+ 'priority' => priority ,
74
81
'arguments' => serialize_arguments ( arguments ) ,
75
82
'locale' => I18n . locale
76
83
}
@@ -99,6 +106,7 @@ def serialize
99
106
def deserialize ( job_data )
100
107
self . job_id = job_data [ 'job_id' ]
101
108
self . queue_name = job_data [ 'queue_name' ]
109
+ self . priority = job_data [ 'priority' ]
102
110
self . serialized_arguments = job_data [ 'arguments' ]
103
111
self . locale = job_data [ 'locale' ] || I18n . locale
104
112
end
0 commit comments