繁体   English   中英

Rails delay_job不执行

[英]Rails delayed_job doesn't perform

我定义了两个自定义作业。 一种有效,另一种无效。 一个没有工作的队列,但是没有其他任何事情发生。 没有失败或成功。

在我找到了文档以及在SO上的collectionidea尝试了所有技巧之后,我很沮丧。 我保留了工作上的失败。 我将所有DJ事件记录在单独的日志中。 他们没有提供任何线索。 我的DJ日志显示正在排队的工作,仅此而已。

工作是发布到网站上。

这是出现在延迟作业表中的不良作业。

2.1.2 :004 > Delayed::Job.last
 => #<Delayed::Backend::ActiveRecord::Job id: 2515456, priority: 0, attempts: 0, handler: "--- !ruby/struct:SendHubCommandJob\ncmd: getOptions...", last_error: nil, run_at: "2015-08-14 02:07:32", locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: "2015-08-14 02:07:32", updated_at: "2015-08-14 02:07:32">

我的自定义工作:

SendHubCommandJob = Struct.new(:cmd, :hub, :badge, :arg1, :arg2) do
  # Send a command to the hub to forward to badge

  def enqueue(job)
    #called
    Delayed::Worker.logger.info "SendHubCommandJob enqueue: #{cmd} #{hub} #{badge} #{arg1} #{arg2}"
  end

  def success(job)
    #not called
    Delayed::Worker.logger.info "SendHubCommandJob: success"
  end

  def error(job, exception)
    #not called
    Delayed::Worker.logger.info "SendHubCommandJob: error"
    # Send email notification / alert / alarm
  end

  def failure(job)
    #not called
    Delayed::Worker.logger.info "SendHubCommandJob: failure"  
  end

  def perform
    #not called
    Delayed::Worker.logger.info "SendHubCommandJob: got here"
    Delayed::Worker.logger.info "SendHubCommandJob perform: #{:cmd} #{hub} #{badge} #{arg1} #{arg2}"

    require "open-uri"
    require "net/http"

    @@cmd_count = @@cmd_count + 1
    s = "http://#{hub}.local:9090/cmd"
    uri = URI(s)
    req = Net::HTTP::Post.new(uri)
    Delayed::Worker.logger.info "SendHubCommandJob: #{uri}"

    # Set where hub should send asynch response
    response_addr = "mark.local:3000"

    #TODO Implement other commands here
    case @cmd
    when 'getOptions'
      req.set_form_data('type' => 'cmd', 'cmd'=>'READ', 'subcmd'=>'GENERAL', 'datatype'=>'OPTIONS', 'modulename'=>'BTPENDANT', 
      'sensorid'=>'#{@badge}', 'moduleidx'=>'0', 'processtype'=>'1', 'count_or_ms'=>'0', 'trackingid'=>@@cmd_count, 'response_addr'=>response_addr,
      'jsontxt'=>{'device'=>'#{@hub}'})

    when 'setOptions'  #arg1 is 12 byte hex string per badge spec
      req.set_form_data('type' => 'cmd', 'cmd'=>'WRITE', 'subcmd'=>'GENERAL', 'datatype'=>'OPTIONS', 'modulename'=>'BTPENDANT', 
      'sensorid'=>'#{@badge}', 'moduleidx'=>'0', 'processtype'=>'1', 'count_or_ms'=>'0', 'trackingid'=>@@cmd_count, 'response_addr'=>response_addr, 
      'jsontxt'=>{'device'=>'#{@hub}', 'value'=>'#{@arg1}'})

    when 'getBadgeInfo'  #arg1 is string DEVICE_NAME, MODEL_NUMBER, SERIAL_NUMBER, FIRMWARE_REV, MANUFACTURER_NAME
      req.set_form_data('type' => 'cmd', 'cmd'=>'READ', 'subcmd'=>'#{@arg1}', 'datatype'=>'ID', 'modulename'=>'BTPENDANT', 
      'sensorid'=>'#{@badge}', 'moduleidx'=>'0', 'processtype'=>'1', 'count_or_ms'=>'0', 'trackingid'=>@@cmd_count, 'response_addr'=>response_addr,
      'jsontxt'=>{'device'=>'#{@hub}'})

    else
      Delayed::Worker.logger.error "SendHubCommandJob: Unexpected command"
    end

    res = Net::HTTP.start(uri.hostname, uri.port) do |http|
      http.request(req)
      #Delayed::Worker.logger.info response.inspect
    end

    case res
      when Net::HTTPSuccess, Net::HTTPRedirection
      # OK
    else
      # TODO figure how handle error
      res.value
    end
    Delayed::Worker.logger.debug "SendHubCommandJob: #{@res.to_s}"
  end  #perform
end

我意识到我没有适当地开始延迟工作的工人。 该命令需要结尾的“开始”:

RAILS_ENV =开发箱/ delayed_job 开始

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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