delayed_job update query is running infinitely

后端 未结 4 737
面向向阳花
面向向阳花 2021-02-13 12:55

I am using delayed_job and delayed_job_active_record for back ground job execution in my rails application. We are using queue based delayed_job. For starting the delayed I am u

相关标签:
4条回答
  • 2021-02-13 13:08

    So this is a query specifically designed for Postgres. Please refer to https://github.com/collectiveidea/delayed_job_active_record/blob/master/lib/delayed/backend/active_record.rb#L57 for why it has to be like that.

    The idea of delayed job is indeed that it will query the db periodically, so the query in your question is expected to be fired as long as the worker is running. This should happen every second and I can't imagine that this has significant influence on the performance of your app.

    Are you running on very limited hardware like a very small virtual machine?

    0 讨论(0)
  • 2021-02-13 13:09

    I think what you meant is that delayed_job polls too frequently (which by the way is every 5 seconds by default) - I know that fills up your log, and seems "infinite".. :)

    If that is what you meant, then I suggest you run the workless gem. It will only start delayed_job on a per need basis. Many people use it to keep their Heroku worker dynos from running idle, but it works just as well in development mode.

    Note that if you are using delayed_job_active_record, you also need to add gem 'daemons' to your Gemfile (daemons). See the Running Jobs section of delayed_job.

    Thus, your Gemfile would contain:

    gem 'delayed_job_active_record'
    gem 'daemons'
    gem 'workless'
    

    If you need more guidance, let me know in the comments below.

    0 讨论(0)
  • 2021-02-13 13:18

    I faced same issue and i resolved it by adding index on queue field.

    def self.up
      create_table :delayed_jobs, :force => true do |table|
      # Add index on queue field
      add_index :delayed_jobs, [:queue], :name => 'delayed_jobs_queue'
    end
    

    For more information visit below document http://himarsh.org/cautions-on-delayed-jobs/

    0 讨论(0)
  • 2021-02-13 13:19

    i had to use AR's silence method, just change in file [path/to/delayed_job_active_record/gem]/delayed_job_active_record-[any.latest.version]/lib/delayed/backend/active_record.rb around line 68:

    count = ready_scope.limit(1).update_all(:locked_at => now, :locked_by => worker.name)
    

    to

    count = silence {ready_scope.limit(1).update_all(:locked_at => now, :locked_by => worker.name)}
    

    dirty solution, i know, but it works... welcome to propose a better wrapper, but for me Job.reserve method there is big enough to kill any thoughts to override it in config/initializers

    0 讨论(0)
提交回复
热议问题