9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/hirefire/workers/resque/worker.rb', line 9
def work(interval = 5.0, &block)
interval = Float(interval)
$0 = "resque: Starting"
startup
loop do
break if shutdown?
::Resque::Job.environment.hire
if not @paused and job = reserve
log "got: #{job.inspect}"
run_hook :before_fork, job
working_on job
if @child = fork
rand procline "Forked #{@child} at #{Time.now.to_i}"
Process.wait
else
procline "Processing #{job.queue} since #{Time.now.to_i}"
perform(job, &block)
exit! unless @cant_fork
end
done_working
@child = nil
else
if (::Resque::Job.jobs + ::Resque::Job.working) == 0
break if ::Resque::Job.environment.fire
end
sleep(interval)
end
end
ensure
unregister_worker
end
|