【问题标题】:why doesn't my delayed job work more than once when being triggered from a rails server?当从 Rails 服务器触发时,为什么我的延迟工作不会多次工作?
【发布时间】:2016-02-08 22:24:05
【问题描述】:

考虑到延迟工作的工人,

class UserCommentsListWorker
  attr_accessor :opts
  def initialize opts = {}
    @opts = opts
  end

  def perform
    UserCommentsList.new(@opts)
  end

  def before job
    p 'before hook', job 
  end

  def after job
    p 'after hook', job
  end

  def success job
    p 'success hook', job
  end

  def error job, exception
    p '4', exception
  end

  def failure job
    p '5', job
  end

  def enqueue job
    p '-1', job
  end

end

当我从 rails 控制台运行 Delayed::Job.enqueue UserCommentsListWorker.new(client: client) 时,我可以获得重复的打印语句序列和适当的延迟作业生命周期,甚至可以打印挂钩,包括来自工作人员的作业成功的反馈。

包括通过标准 rails 控制器端点运行 worker 的相同调用;

include OctoHelper
include QueryHelper
include ObjHelper
include StructuralHelper

class CommentsController < ApplicationController
  before_filter :authenticate_user!

  def index
    if params['updateCache'] == 'true'
      client = build_octoclient current_user.octo_token
      Delayed::Job.enqueue UserCommentsListWorker.new(client: client)
    end
  end
end

我注意到工作人员将运行并创建延迟的作业,但没有调用任何挂钩并且工作人员从不将作业记录为已完成。

注意截图,

作业 73、75、76 都是通过往返上述端点触发的,而作业 74 是通过 rails 控制台触发的,我的设置有什么问题和/或在此过程中我没有注意到什么?我要强调的是,网络服务器第一次访问上述控制器端点时,作业排队并正常运行,但作业应该正常运行的所有后续实例似乎什么也没做,并且在此过程中没有给我任何反馈。

我还要强调我从未看到失败、错误或排队挂钩运行。

谢谢:)

【问题讨论】:

    标签: ruby-on-rails delayed-job


    【解决方案1】:

    这个问题的答案的长短是,如果你注意到,我试图在延迟的作业通知中存储一个 client 对象,这会导致问题,因此,不要将复杂的对象存储在这份工作,只需使用基本数据 ID 1 或字符串 foo 或布尔值 true 等。capisce?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-06
      • 2022-08-18
      • 2015-09-10
      • 2015-10-08
      • 2011-01-06
      • 1970-01-01
      • 2019-03-16
      • 1970-01-01
      相关资源
      最近更新 更多