Skip to content

Commit 7188ef1

Browse files
committed
Refactor @cant_fork and $TESTING. We need separate control in the next commit to prevent invocation of before_hook when in fact we don't fork.
1 parent ef04bfd commit 7188ef1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/resque/worker.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ def work(interval = 5.0, &block)
148148
nil
149149
end
150150
else
151-
unregister_signal_handlers if !@cant_fork && term_child
151+
unregister_signal_handlers if will_fork? && term_child
152152
procline "Processing #{job.queue} since #{Time.now.to_i}"
153153
redis.client.reconnect # Don't share connection with parent
154154
perform(job, &block)
155-
exit! unless @cant_fork
155+
exit! if will_fork?
156156
end
157157

158158
done_working
@@ -229,14 +229,12 @@ def queues
229229
# Not every platform supports fork. Here we do our magic to
230230
# determine if yours does.
231231
def fork
232-
@cant_fork = true if $TESTING
233-
234232
return if @cant_fork
235233

236234
begin
237235
# IronRuby doesn't support `Kernel.fork` yet
238236
if Kernel.respond_to?(:fork)
239-
Kernel.fork
237+
Kernel.fork if will_fork?
240238
else
241239
raise NotImplementedError
242240
end
@@ -507,6 +505,10 @@ def working?
507505
def idle?
508506
state == :idle
509507
end
508+
509+
def will_fork?
510+
!(@cant_fork || $TESTING)
511+
end
510512

511513
# Returns a symbol representing the current worker state,
512514
# which can be either :working or :idle

0 commit comments

Comments
 (0)