【问题标题】:Rails 5 - Resque not processing enqueued jobRails 5 - Resque 不处理排队的作业
【发布时间】:2016-09-22 10:38:08
【问题描述】:

我正在尝试使用Resque 1.26.0(和Redis-rb 3.3.1)来完成一项简单的工作。该作业似乎没有处理 perform 函数,因为 resque-web 正在处理每个作业并显示 0 个失败。这些作业也正在即时处理。

作业从控制器动作中排入队列

Resque.enqueue(TestJob, url)

工作本身的样子

class TestJob < ApplicationJob
  @queue = :tags_queue
  Logger.new("log/resque_worker_QUEUE.log").fatal("thing")

  def self.perform(url)
    Logger.new("log/resque_worker_QUEUE.log").fatal("other thing")
    logger.fatal("more errors please")

    myDivideByZeroVar= 1/0
    raise "error"
    Logger.new("log/resque_worker_QUEUE.log").fatal("other thing")
    logger.fatal("more errors please")
  end
end

还设置了一个rake任务:

require 'resque/tasks'
task "resque:setup" => :environment

redis-server 正在运行。

worker 以rake resque:work QUEUE=* 启动。使用详细日志不会显示任何有用的信息。

日志文件只显示第一个致命错误字符串“thing”。 perform 内的其他错误均未记录。

我在这里做错了什么?

【问题讨论】:

  • 在 resque web 中:你有多少正在运行的工人?每次运行Resque.enqueue(TestJob, url) 时处理数是否会增加?
  • 有一名工人正在运行。每次调用 Resque.enqueue 时处理次数都会增加,但会立即处理。
  • 您是否尝试在 perform 方法的第一行中包含 byebug ?
  • 是的。它没有启动调试器。 perform 根本没有运行。
  • 要启用 resque 作为活动作业适配器,我们应该在我们的 rails 应用程序配置(config/application.rb、config/development.rb 或 config/production.rb)中添加 config.active_job.queue_adapter = :resque

标签: ruby-on-rails ruby redis jobs resque


【解决方案1】:

解决了这个问题。需要使用 ActiveJob 而不是 Resque.enqueue 调用作业。 TestJob.perform_later(url) 工作得很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    相关资源
    最近更新 更多