我定义了两个自定义作业。一个有效,另一个没有。那个不工作的人会入队,但没有其他任何事情发生。没有失败或成功。
在我找到文件的集体区域尝试了所有的提示之后,我很难过。我保留了工作失败。我将所有DJ事件记录在一个单独的日志中。他们没有提供任何线索。我的DJ日志显示了正在排队的工作。
工作是发布到网站。
这是deb_job表中显示的错误作业。
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
答案 0 :(得分:1)
我意识到我没有正确地启动延迟的工作。该命令需要跟踪&#34;开始&#34;:
RAILS_ENV =开发区/ delayed_job 开始