I'm currently using Workflow.
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
Now, I can do:
l = Link.new
l.process!
l.process!
l.process!
l.process!
# n times l.process! (in a loop, or cron job for example)
But it can happens, some link will not respond or give me an invalid response durning the checking process.
How I can conditionally switch to another state ?
I mean something like this:
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