[DDD/CQRS] Schedule future events

594 views
Skip to first unread message

Mattias Brand

unread,
Jan 10, 2012, 4:21:51 PM1/10/12
to ddd...@googlegroups.com
Given an open Store (AR), when I issue a close command with a date in the future when the Store is going to be closed; I want one event (StoreClosing) triggered immediately telling the AR it's going to be closed in the future and then an event (StoreClosed) triggered when that actual closing date occurs. How would you go about doing this?

I've considered a ScheduleService which basically "holds" an event until the time is up to then apply it to the AR. (inspired from Greg Youngs way of solving Timeouts in sagas)

I also considered dropping the future event (StoreClosed) since it doesn't add anything to the AR (it can already deduce that it is closed from the StoreClosing event although this makes it crucial that the server clock is stable) and instead schedule the actions that is supposed to happen at the closing date when the StoreClosing event is triggered.


Can someone think outside the box for me? I feel I'm missing something obvious.

Caleb Vear

unread,
Jan 10, 2012, 4:54:00 PM1/10/12
to ddd...@googlegroups.com
I think I would have a saga triggered by the StoreClosing event.  The saga would send a CloseStore command to the ScheduleService which would send the command on the date the store is closing.

Caleb

Rinat Abdullin

unread,
Jan 11, 2012, 5:11:32 AM1/11/12
to ddd...@googlegroups.com
Just a clarification. You can't schedule a future event StoreClosed (events define something that has already happened), however you can schedule a command to be executed later (CloseStore @ 8PM today). Then the store AR can decide if it handles the command or silently ignores it (i.e. if it does not make sense).

If you are interested, you can check "Lokad.CQRS Sample project" for a sample implementation of timer service, that we are using to "power" sagas (search for SimpleTimerService_Usage.cs). Or you can use any cron implementation for that.

Best,
Rinat

@yreynhout

unread,
Jan 11, 2012, 5:17:18 AM1/11/12
to DDD/CQRS
Drop the StoreClosed event (it's a means to an end) and subscribe to
the StoreClosing event. Using either a saga (as Caleb suggests) or a
scheduler, trigger the actions that are supposed to happen upon the
closing date. Nothing missing here.
Reply all
Reply to author
Forward
0 new messages