【问题标题】:resque-status and resque-scheduler for recurring jobsresque-status 和 resque-scheduler 用于重复工作
【发布时间】:2012-11-07 19:35:41
【问题描述】:

我的 resque 系统有以下配置(没有 Rails,只有 Sinatra 基础),其中我有一堆从 yml 文件安排的重复作业

resque (1.23.0)
resque-scheduler (2.0.0)
resque-status (0.4.0)

重复计划出现在“计划”选项卡上,当我单击“立即排队”按钮时,状态也出现在“状态”选项卡上,问题是当重复作业自动运行时,它们不会出现在“状态”选项卡上。我的 resque_schedule.yml 看起来像这样

email_notifier:
  every: 5m
  custom_job_class: Process_Notification_Emails
  queue: email_notifier
  args: 
  description: "Process mail notifications"

注意:这些计划的作业实际上每 5 分钟运行一次,并且按预期运行,我遇到的唯一问题是除非我手动将它们排入队列,否则它们不会出现在“状态”选项卡上

任何想法我在这里做错了什么?

【问题讨论】:

    标签: ruby resque


    【解决方案1】:

    支持 resque-status(和其他自定义作业)

    一些 Resque 扩展,如 resque-status 使用自定义作业类 API 签名略有不同。 Resque-scheduler 并没有尝试 支持所有现有和未来的自定义作业类,而不是它 支持计划标志,因此您可以扩展自定义类并制作 它支持预定的工作。

    假设我们有一个名为 FakeLeaderboard 的 JobWithStatus 类

    class FakeLeaderboard < Resque::JobWithStatus
      def perform
        # do something and keep track of the status
      end
    end
    

    然后是时间表:

    create_fake_leaderboards:
      cron: "30 6 * * 1"
      queue: scoring
      custom_job_class: FakeLeaderboard
      args:
      rails_env: demo
      description: "This job will auto-create leaderboards for our online demo and the status will update as the worker makes progress"
    

    如果您的扩展程序不支持预定作业,您需要 扩展自定义作业类以支持#scheduled 方法:

    module Resque
      class JobWithStatus
        # Wrapper API to forward a Resque::Job creation API call into
        # a JobWithStatus call.
        def self.scheduled(queue, klass, *args)
          create(*args)
        end
      end
    end
    

    https://github.com/bvandenbos/resque-scheduler#support-for-resque-status-and-other-custom-jobs

    【讨论】:

    • 感谢您的回复,但我已经使用了支持 resque-scheduler 的最新版本的 resque-status(直接来自 git master),它确实实现了预定的方法...请采取看看这个github.com/quirkey/resque-status/blob/master/lib/resque/plugins/…
    • 你在调用scheduled方法吗? WorkingJob.scheduled(:queue_name, WorkingJob, @job_args) 之类的东西?
    猜你喜欢
    • 2011-01-25
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 2013-12-05
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多