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:
662662
663663Now everyone is on the same page.
664664
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+
665670
666671Plugins and Hooks
667672-----------------
Original file line number Diff line number Diff line change @@ -118,6 +118,17 @@ def to_s
118118 "Resque Client connected to #{ redis_id } "
119119 end
120120
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
121132
122133 #
123134 # queue manipulation
@@ -255,8 +266,8 @@ def reserve(queue)
255266
256267 # Validates if the given klass could be a valid Resque job
257268 #
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+ #
260271 # If given klass is nil this method will raise a `Resque::NoClassError`
261272 def validate! ( klass )
262273 Job . validate! ( klass )
Original file line number Diff line number Diff line change @@ -42,10 +42,16 @@ def initialize(queue, payload)
4242 def self . create ( queue , klass , *args )
4343 validate! ( klass , queue )
4444
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+
4651 Plugin . after_enqueue_hooks ( klass ) . each do |hook |
4752 klass . send ( hook , *args )
4853 end
54+
4955 ret
5056 end
5157
Original file line number Diff line number Diff line change 88 Resque . push ( :people , { 'name' => 'bob' } )
99 Resque . push ( :people , { 'name' => 'mark' } )
1010 end
11-
11+
1212 test "can set a namespace through a url-like string" do
1313 assert Resque . redis
1414 assert_equal :resque , Resque . redis . namespace
237237 Resque . decode ( "{\" error\" :\" Module not found \\ u002\" }" )
238238 end
239239 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
240250end
You can’t perform that action at this time.
0 commit comments