简体   繁体   中英

Heroku resque/clockwork 'No job defined for class'

I am trying to run a background job on Heroku using Resque/Clockwork.

Locally, jobs are queued by Clockwork and executed by Resque as expected. On Heroku, sometimes it works... but most of the time Clockwork queues the job as expected, and when executed by Resque I get a failed job with the error 'No job defined for class'.

The exact error that shows up through the Resque admin panel is:

Worker 960f8a1b-cce9-497a-a7ab-9b40c166a600:2+1 on FEATURED_CATALOG_ITEMS_CACHE at 27 minutes ago     Retry or Remove
Class nil
Arguments nil
Exception Error
Error No job defined for class 'Workers::FeaturedCatalogItemsCacheWorker'

My code looks like:

class Workers::FeaturedCatalogItemsCacheWorker

  @queue = :featured_catalog_items_cache

  def self.perform
    p 'do work' # there is more code here but edited for brevity
  end
end

require File.expand_path('../../config/boot',        __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'clockwork'

module Clockwork
  every(2.minutes, 'Queueing FeaturedCatalogItemsCacheWorker job') { Resque.enqueue(Workers::FeaturedCatalogItemsCacheWorker) }
end

require 'resque/tasks'

task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end

web: rackup -p $PORT
resque: env TERM_CHILD=1 bundle exec rake resque:work
clock: bundle exec clockwork lib/clock.rb

Am I missing something?

maybe in /lib/clock.rb

require 'Workers::FeaturedCatalogItemsCacheWorker'

Solution :

require './config/boot' require './config/environment' require 'clockwork' require 'resque'

module Clockwork

handler do |job| puts "Running job : #{job}" Resque.enqueue(job) end

every(15.minutes, NewsRssReader ) end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM