Answer the question
In order to leave comments, you need to log in
How to implement delayed events?
Hey!
I'm trying to beautifully implement the mechanism of deferred events in an architecture with a DDD approach. By deferred, I mean those events that are not initiated directly by user commands, but must occur later. As an example: there is a site where the user aggregate has a date of birth. We want to congratulate him on this day by sending a letter. In addition, in the limited context of the store, this user must have bonuses credited to the account. The starting point of the algorithm is the moment when the user indicates the date of birth in the profile.
Reflecting on the task, I came to the conclusion that it is better to move work with time into a separate Scheduler context, which will twitch the crown from the outside. There are several options for how this scheduler interacts with other contexts.
1. At the moment when the user specifies the date of birth, we plan specific commands, further pseudocode
Scheduler->schedule(new SendHappyBirthdayEmail($email), $birthdate);
Scheduler->schedule(new IncreaseBonuses($user, $amount), $birthdate);
$userId = 'j123jjkh3j2jh3j2h';
$key = 'user_birthdate:' : $userId;;
Scheduler->schedule($key, $birthdate);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question