0
我目前使用Workflow。現在statemachine,條件轉換
class Link < ActiveRecord::Base
include Workflow
workflow do
state :new do
event :process, :transitions_to => :checking #checking http_response_code & content_type
end
state :checking do
event :process, :transitions_to => :fetching_links # fetching all links
end
state :fetching_links do
event :process, :transitions_to => :checking #ready for next check
end
end
end
,我可以這樣做:
l = Link.new
l.process!
l.process!
l.process!
l.process!
# n times l.process! (in a loop, or cron job for example)
但它可偏偏,有些鏈接將不響應,或者給我一個無效響應德寧檢查過程。
我如何有條件地切換到另一個狀態?
我的意思是這樣的:
class Link < ActiveRecord::Base
include Workflow
workflow do
state :new do
event :process, :transitions_to => :checking #checking http_response_code & content_type
end
state :checking do
event :process, :transitions_to => :fetching_links # if all is fine
event :process, :transitions_to => :failded # if something goes wrong
end
state :fetching_links do
event :process, :transitions_to => :checking #ready for next check
end
end
end