0
我已經定義了兩個自定義作業。一個工作,另一個不工作。沒有工作的人排隊,但沒有發生任何事情。沒有失敗或成功。Rails delayed_job不執行
在我發現了文檔和SO的所有關於collectiveidea的提示後,我很難過。我保留了工作失敗。我將所有DJ事件記錄在單獨的日誌中。他們沒有提供線索。我的DJ日誌顯示正在排隊的工作,就是這樣。
這項工作是張貼到一個網站。
這是出現在delayed_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
它排入事實,但從來沒有執行建議,我們應該看看工人。你用什麼命令啓動你的DJ工作人員? –
謝謝羅伯特。 RAILS_ENV =開發bin/delayed_job。我檢查並且delayed_job是一個正在運行的進程。 –