J'utilise actuellement Workflow.statemachine, transitions conditionnelles
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
Maintenant, je peux faire:
l = Link.new
l.process!
l.process!
l.process!
l.process!
# n times l.process! (in a loop, or cron job for example)
Mais il peut se produit, un lien ne répond pas ou me donner une réponse invalide Durning la procédure de vérification.
Comment puis-je passer à un autre état sous condition?
je veux dire quelque chose comme ceci:
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