public
Description: Database based asynchronously priority queue system -- Extracted from Shopify
Homepage: http://www.shopify.com
Clone URL: git://github.com/tobi/delayed_job.git
delayed_job / tasks / jobs.rake
100644 29 lines (20 sloc) 0.554 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
namespace :jobs do
               
  task :work => :environment do
    
    SLEEP = 5
     
    trap('TERM') { puts 'Exiting...'; $exit = true }
    trap('INT') { puts 'Exiting...'; $exit = true }
 
    loop do
      
      count = 0
 
      realtime = Benchmark.realtime do
        count = Delayed::Job.work_off
      end
 
      break if $exit
 
      if count.zero?
        sleep(SLEEP)
      else
        RAILS_DEFAULT_LOGGER.info "#{count} jobs completed at %.2f j/s ..." % [count / realtime]
      end
      
      break if $exit
    end
  end
end