Periodic Listeners
Periodic listeners are event listeners that trigger at specific time intervals. They are useful for tasks that need to be executed regularly, such as quality of service metrics/uptime checkers, data updates, and subscription style services.
Overview
Periodic Listeners enable your blueprint to:
- Schedule tasks to run at specific intervals
- Execute background jobs periodically
- Perform regular checks or updates without manual intervention
Periodic Listeners are particularly useful for tasks such as:
- Regular data synchronization
- Scheduled maintenance operations
- Periodic health checks
- Automated reporting at set intervals
PeriodicEventListener
Some programs may only be interested in checking for events at regular intervals. In this case, the PeriodicEventListener
can be used to simplify the process.
A PeriodicEventListener
is a wrapper that takes 4 type parameters:
MSEC
: The number of milliseconds between each event check.T
: The inner event listener typeCtx
: The context typeEvent
: The event type
We can make a PeriodicEventListener
that ticks every 6000ms to check the status of a web server using reqwest (opens in a new tab).
Start by defining our inner event listener (T
= WebPoller
, in this case), and implement the EventListener
trait.
Using it in a Blueprint
Implement the pre-processor and post-processors for the event listener:
Integrate the event listener inside the job
: