Automatic transistion after a certain period of time

58 views
Skip to first unread message

Clement D

unread,
Jul 25, 2013, 6:25:00 AM7/25/13
to pluginaw...@googlegroups.com

I am currently developing a Rails app and I am using the state_machine gem to guide the customer through a complex process.

At multiple states of the process, I need to trigger events after a certain period time. For instance, if the customer hasn't confirmed he received his order after 5 days I'd like to automatically send him an email and enter in a parcel tracking process.

class Order < ActiveRecord::Base



    state_machine :initial => :confirmed do

        after_transition :on => :not_received_by_5_days, do |order, transition|
            order.send_email
            order. .....
            order. .....

end

  event :customer_confirmation do transition :confirmed => :order_received end event :not_received_by_5_days do transition :confirmed => :parcel_tracking_process end def send_email blabla end end end


How can I trigger transition after a certain period of time?

Thank you,

Clément

Andrew Havens

unread,
Dec 17, 2013, 2:38:27 PM12/17/13
to pluginaw...@googlegroups.com
I'm wondering how to do this same thing. I have a model that is stuck in a "processing" state. I think in your case, it sounds like you will need something external to check the state of your Orders (like a cron job, or Resque/Sidekiq job) that can check a "confirmation date" is 5 days in the past and to manually transition to a new state. I'm completely new to working with state_machine, so I'm not familiar with the syntax to transition to a valid state.
Reply all
Reply to author
Forward
0 new messages