In a setup where multiple instances of an application are running simultaneously, it is imperative to make sure only one of those instances can start the execution of a scheduled job. However, in a scenario where the tasks of the scheduled job are not only heavy but also voluminous, it is important to find a way to distribute their execution to the multiple running instances. For example, a platform that is heavy on daily report generation, notification, and transfer to hundreds of thousands of users. This reporting will be a scheduled operation that needs to be concluded as fast as possible due to time constraints on the users’ business operation. There is, therefore, a need to trigger this scheduled job and preferably complete the execution within an acceptable duration. This is different from the use case described here.
A feasible approach to handle the scenario described above is through the combination of Jobrunr and Shedlock. Jobrunr excels at executing fire-and-forget tasks of any scale while Shedlock makes sure that execution happens at most once at the same time. Shedlock ensures that only a single running instance of the application (out of as many as possible) can start a scheduled job while Jobrunr makes sure the tasks of the scheduled job are distributed to the instances if needed.
Implementation source code and instructions on how to run it: Here
References:
- https://www.youtube.com/watch?v=2KFeeFuM9og
- Feature image by Jake Givens on Unsplash
Leave a comment