首次設置延遲作業,並且在執行RailsCast後,它不能在我的測試環境中工作。延遲作業失敗,無日誌或提醒
我有兩種方法,我想運行 - 在測試中,我想在頁面加載後15秒運行它們。這些方法是來自Participation.rb模型的calculate_rankings
和update_wallet
。
安裝每個引導創業板上面之後,我想兩件事情調試:1)我正在rake jobs:work
,那裏是Starting job worker
後無輸出,和2)我已經添加了警報到我的控制器的方法,該方法不激活。
後寶石安裝和運行遷移(這是成功的),我已經在代碼中做了兩處更改。
創建應用程序/工作/ chipsupdater.rb
這是錯誤。該文件被錯誤地命名,因此在控制器中沒有正確調用。根據我在下面寫的方法,應該是app/jobs/chips_update_job.rb。
class ChipsUpdaterJob < Struct.new(:game_id)
def perform
Participation.calculate_ranking(game_id)
Participation.update_wallet(game_id)
end
end
更新我的ScoreboardController,我要初始化延遲工作:
class ScoreboardController < ApplicationController def index @participations = Participation.where(finished: true, game_id: session[:game_id]).order(score: :desc).limit(10) @game = Game.find(params[:game_id]) end def chipsupdater Delayed::Job.enqueue(ChipsUpdaterJob.new(params[:game_id]), :run_at => 1.minute.from_now) flash[:notice] = "Things are good. Not broken." end end
隨着作業沒有閃光燈警報或輸出控制檯,我的信念是我沒有正確地調用延遲作業。你能發現我出錯的地方嗎(或者爲什麼我不能使用作業控制檯進行調試)?
編輯
每註釋中的討論,我現在運行在測試環境中的工人。但是,我仍然無法a)將作業發佈到我的DelayedJobs
表或b)實現我們的關鍵輸出,即在ChipsUpdater作業文件中使用這兩種方法。
因此,我的觀點是,我無法根據此故障正確調用延遲的作業。
對於上下文,我想包含兩個更多可能相關的文件。
首先,這裏是在ChipUpdaterJob
引用的參與模式:
class Participation < ActiveRecord::Base
ef self.calculate_ranking(game_id)
records = Participation.where(game_id: game_id, finished: true).order('score DESC, updated_at ASC')
records.each_with_index do |record, index|
puts "rank: #{index + 1}"
puts record.inspect
puts record['score']
puts record['user_id']
puts record['game_id']
Ranking.create(game_id: game_id, user_id: record['user_id'], game_time: record['updated_at'], ranking: index + 1)
end
end
如果取出延遲上下文和運行從記分板控制器正常的方法,我在當地證實,它成功運行排名過程。延遲似乎是失敗的。
/斌/ delayed_job的
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize
對於任何檢查這一點,delayed_job的不正確的,因爲我有我的工作文件夾中的不正確命名的文件發佈。下劃線是正確調用控制器中類的關鍵。 – darkginger