@@ -133,13 +133,38 @@ def watch_queue(queue)
133
133
# If either of those conditions are met, it will use the value obtained
134
134
# from performing one of the above operations to determine the queue.
135
135
#
136
- # If no queue can be inferred this method will return a non-true value.
136
+ # If no queue can be inferred this method will raise a `Resque::NoQueueError`
137
137
#
138
138
# This method is considered part of the `stable` API.
139
139
def enqueue ( klass , *args )
140
- queue = klass . instance_variable_get ( :@queue )
141
- queue ||= klass . queue if klass . respond_to? ( :queue )
142
- Job . create ( queue , klass , *args )
140
+ Job . create ( queue_from_class ( klass ) , klass , *args )
141
+ end
142
+
143
+ # This method can be used to conveniently remove a job from a queue.
144
+ # It assumes the class you're passing it is a real Ruby class (not
145
+ # a string or reference) which either:
146
+ #
147
+ # a) has a @queue ivar set
148
+ # b) responds to `queue`
149
+ #
150
+ # If either of those conditions are met, it will use the value obtained
151
+ # from performing one of the above operations to determine the queue.
152
+ #
153
+ # If no queue can be inferred this method will raise a `Resque::NoQueueError`
154
+ #
155
+ # If no args are given, this method will dequeue *all* jobs matching
156
+ # the provided class. See `Resque::Job.destroy` for more information.
157
+ #
158
+ # This method is considered part of the `stable` API.
159
+ def dequeue ( klass , *args )
160
+ Job . destroy ( queue_from_class ( klass ) , klass , *args )
161
+ end
162
+
163
+ # Given a class, try to extrapolate an appropriate queue based on a
164
+ # class instance variable or `queue` method.
165
+ def queue_from_class ( klass )
166
+ klass . instance_variable_get ( :@queue ) ||
167
+ ( klass . respond_to? ( :queue ) and klass . queue )
143
168
end
144
169
145
170
# This method will return a `Resque::Job` object or a non-true value
0 commit comments