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
Search Repo:
delayed_job / tasks / jobs.rake
100644 36 lines (25 sloc) 0.879 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
30
31
32
33
34
35
36
namespace :jobs do
  
               
  task :work => :environment do
 
    puts "*** Starting job worker #{Delayed::Job.worker_name}"
    
    SLEEP = 5
     
    trap('TERM') { puts 'Exiting...'; $exit = true }
    trap('INT') { puts 'Exiting...'; $exit = true }
 
    loop do
      result = nil
  
      realtime = Benchmark.realtime do
        result = Delayed::Job.work_off
      end
  
      count = result.sum
    
      break if $exit
  
      if count.zero?
        sleep(SLEEP)
        puts 'Waiting for more jobs...'
      else
        status = "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result.last]
        RAILS_DEFAULT_LOGGER.info status
        puts status
      end
    
      break if $exit
    end
  end
end