Note that there are some explanatory texts on larger screens.

plurals
  1. POState machine transitions at specific times
    primarykey
    data
    text
    <p>Simplified example:</p> <p>I have a to-do. It can be future, current, or late based on what time it is.</p> <pre><code> Time State 8:00 am Future 9:00 am Current 10:00 am Late </code></pre> <p>So, in this example, the to-do is "current" from 9 am to 10 am.</p> <p>Originally, I thought about adding fields for "current_at" and "late_at" and then using an instance method to return the state. I can query for all "current" todos with <code>now &gt; current and now &lt; late</code>.</p> <p>In short, I'd calculate the state each time or use SQL to pull the set of states I need.</p> <p>If I wanted to use a state machine, I'd have a set of states and would store that state name on the to-do. But, how would I trigger the transition between states at a specific time for each to-do? </p> <ul> <li>Run a cron job every minute to pull anything in a state but past the transition time and update it</li> <li>Use background processing to queue transition jobs at the appropriate times in the future, so in the above example I would have two jobs: "transition to current at 9 am" and "transition to late at 10 am" that would presumably have logic to guard against deleted todos and "don't mark late if done" and such.</li> </ul> <p>Does anyone have experience with managing either of these options when trying to handle a lot of state transitions at specific times?</p> <p>It feels like a state machine, I'm just not sure of the best way to manage all of these transitions.</p> <p>Update after responses:</p> <ul> <li>Yes, I need to query for "current" or "future" todos</li> <li>Yes, I need to trigger notifications on state change ("your todo wasn't to-done")</li> </ul> <p>Hence, my desire to more of a state-machine-like idea so that I can encapsulate the transitions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload