File tree Expand file tree Collapse file tree 4 files changed +36
-4
lines changed Expand file tree Collapse file tree 4 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -662,6 +662,11 @@ this way we can tell our Sinatra app about the config file:
662
662
663
663
Now everyone is on the same page.
664
664
665
+ Also, you could disable jobs queueing by setting 'inline' attribute.
666
+ For example, if you want to run all jobs in the same process for cucumber, try:
667
+
668
+ Resque.inline = ENV['RAILS_ENV'] == "cucumber"
669
+
665
670
666
671
Plugins and Hooks
667
672
-----------------
Original file line number Diff line number Diff line change @@ -118,6 +118,17 @@ def to_s
118
118
"Resque Client connected to #{ redis_id } "
119
119
end
120
120
121
+ # If 'inline' is true Resque will call #perform method inline
122
+ # without queuing it into Redis and without any Resque callbacks.
123
+ # The 'inline' is false Resque jobs will be put in queue regularly.
124
+ def inline?
125
+ @inline
126
+ end
127
+ alias_method :inline , :inline?
128
+
129
+ def inline = ( inline )
130
+ @inline = inline
131
+ end
121
132
122
133
#
123
134
# queue manipulation
@@ -255,8 +266,8 @@ def reserve(queue)
255
266
256
267
# Validates if the given klass could be a valid Resque job
257
268
#
258
- # If no queue can be inferred this method will raise a `Resque::NoQueueError`
259
- #
269
+ # If no queue can be inferred this method will raise a `Resque::NoQueueError`
270
+ #
260
271
# If given klass is nil this method will raise a `Resque::NoClassError`
261
272
def validate! ( klass )
262
273
Job . validate! ( klass )
Original file line number Diff line number Diff line change @@ -42,10 +42,16 @@ def initialize(queue, payload)
42
42
def self . create ( queue , klass , *args )
43
43
validate! ( klass , queue )
44
44
45
- ret = Resque . push ( queue , :class => klass . to_s , :args => args )
45
+ if Resque . inline?
46
+ ret = constantize ( klass ) . perform ( *decode ( encode ( args ) ) )
47
+ else
48
+ ret = Resque . push ( queue , :class => klass . to_s , :args => args )
49
+ end
50
+
46
51
Plugin . after_enqueue_hooks ( klass ) . each do |hook |
47
52
klass . send ( hook , *args )
48
53
end
54
+
49
55
ret
50
56
end
51
57
Original file line number Diff line number Diff line change 8
8
Resque . push ( :people , { 'name' => 'bob' } )
9
9
Resque . push ( :people , { 'name' => 'mark' } )
10
10
end
11
-
11
+
12
12
test "can set a namespace through a url-like string" do
13
13
assert Resque . redis
14
14
assert_equal :resque , Resque . redis . namespace
237
237
Resque . decode ( "{\" error\" :\" Module not found \\ u002\" }" )
238
238
end
239
239
end
240
+
241
+ test "inlining jobs" do
242
+ begin
243
+ Resque . inline = true
244
+ Resque . enqueue ( SomeIvarJob , 20 , '/tmp' )
245
+ assert_equal 0 , Resque . size ( :ivar )
246
+ ensure
247
+ Resque . inline = false
248
+ end
249
+ end
240
250
end
You can’t perform that action at this time.
0 commit comments