Workling労働者さんで新たに追加記録
-
19-09-2019 - |
質問
私が使っているスターリングおよびWorkling処理の課題の背景に私は、アプリケーションSwoopo-オークションサイトです。この場合、バックグラウンドタスクが通知システムを監視するため、オークションおよび通知の発表をすることがあります。モニターの呼び出し時の作成のオークションオブジェクトです。私の問題は私のモニタコードを含んでいるのが、オークション本イベントは終了いたしました。。こちらのコード:
単体テストにエラーが発生した場合:
class AuctionTest < ActiveSupport::TestCase
test "are monitored when created" do
auction = Auction.new(
:name => "A TV",
:markdown => "A large TV",
:starting_bid => 0.01,
:bid_increment => 0.01,
:starts_at => Time.now(),
:ends_at => Time.now() + 5.seconds,
:active => true
)
auction.save
Bid.place(@current_user, auction)
sleep(10) #when bids are placed, time is added to the end of the auction so wait
assert auction.won?
assert_equal @current_user.id, auction.winner_id
end
end
作業者コード
class AuctionsWorker < Workling::Base
def monitor(options)
active = true
ends_at = options[:original_ends_at]
while active
auction = Auction.find(options[:auction_id]) #this is the record that cannot be found
if auction.won?
active = false
winner = User.find(auction.high_bidder).id
auction.update_attribute(:winner_id, winner)
else
until Time.now() >= ends_at
sleep(1)
end
end
end
end
end
エクスポートするコードの労働者:
class Auction < ActiveRecord::Base
def after_create
AuctionsWorker.asynch_monitor(:auction_id => self.id, :original_ends_at => self.ends_at) if self.active?
end
end
毎回実行し、試験、受信エラーに聞かせていただきましては、オークションに供給される労働者ができないものにします。
いいアイデア、浮かぶのでしょうか。を使用していレール2.3.5,sqlite3、最新のスターリング,Worklingや、その他のすべての関連するジェムは、Mac OSX10.6.2Macbook Proの場で役立っています。
ありがとうございました。
解決
きdownvotedを作成する"swoopo-スタイル"オークションし、汚れをします。
after_create()でとても間近に見ることができ ます。保存新しいオブジェクトな 保存されてい あり(無記録が存在する)
でafter_createは決の記録になって作成されていない。
http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#M002142
として追加できる身分証明書の分野において、workling過程の検索dbにそのid、寝数秒毎時を探知していないのではないので(一部のプリセットに失敗限り正確に記入してください。
あ-きみの一つに数after_commitプラグインがgithubから"と呼ばれるデータベースを更新しました。
こちらは: