Rails / delayed_job - want to load newest version of job class

前端 未结 2 1634
情话喂你
情话喂你 2021-01-15 20:42

I\'m using the delayed_job plugin in Rails to do background processing, and I\'m experiencing a hiccup in the \'agile development\' I\'ve been experiencing so far in Rails..

2条回答
  •  粉色の甜心
    2021-01-15 21:35

    I use this hack that seams to work quite nice, but be aware that it's probably very Rails and delayed_job version specific so you probably need to change some things. Tested with Rails 3.2.0 and delayed_job 2.1.4.

    Put this into e.g. script/delayed_job_development and run it from the Rails root.

    #!/usr/bin/env ruby
    
    require File.expand_path('../config/environment', File.dirname(__FILE__))
    require 'delayed/worker'
    require "rails/console/app"
    
    class DummyConsoleClass
      include Rails::ConsoleMethods
    end
    dummy_console = DummyConsoleClass.new
    
    worker = Delayed::Worker.new({:quiet => false})
    
    puts "Waiting for jobs..."
    loop do
      if Delayed::Job.find_available(worker.name).count > 0
        puts "Found jobs"
        dummy_console.reload!
        loop do
          break if worker.work_off.sum == 0
        end
        puts "Done, waiting for jobs..."
      end
      sleep(2)
    end
    

    Please comment if you know that this is a very bad idea or things to be aware of, I mainly use it when editing and testing jobs that run immediately not with jobs scheduled to run long into the future.

提交回复
热议问题