Reputation: 141
I'm working on a user story whereby a Task (an entity) is created for a user to work on when a date is overdue and other criteria are met (on a separate entity - let's say a Product).
Ideally I would like a Domain Event to be created in real-time when this "Date" is overdue - however there isn't any trigger I can use in code to do this. I can only really see one type of pattern to use at the moment - that is to have a windows service which is polling every hour (using Topshelf / Quartz for example), pulling back all the records using the Product repository then code to check whether or not the dates are overdue and the criteria are met. If successful, the Domain Event will be triggered and the Task will be created.
As you can imagine, I don't particularly like this. It's not in real-time, and I'm pulling back a lot of data to achieve something relatively simple. Am I missing a trick here? Some kind of state machine / workflow? What architectural patterns / good designs are available for me to utilize in this situation?
Apologies if the question is a little vague, and I'll attempt to clarify if needs be.
Upvotes: 3
Views: 988
Reputation: 18034
If you use a sophisticated scheduler like Quartz anyway, why not just use it to call back to your application at the exact time the Task gets overdue? I've never used Quartz in this way, but I think this should be possible.
To get a robust solution, you might want to consider checking regularly in addition to the on-time callbacks, but I'd expect that these regular checks can run on a low frequency basis.
In any case, when you receive a callback, you need to check which tasks are really overdue. If polling the DB for this check is a performance problem (which I wouldn't expect it is in most cases), you can always cache the upcoming deadlines. Make sure you refresh the cache appropriately, e.g. by listening to the "task published" domain events.
Upvotes: 1