Custom schedule of email notifications
This ticket adds support for user-defined schedule for running KPINotifications
. Instead of fixed @Scheduled
on the method in code, we allow the Administrator to define a custom schedule.
The custom schedule is stored in @Table("notification_schedule") public class NotificationSchedule extends VersionedModel
entity. It's properties include:
- the cron expression
String cron
- the bean
String generator
and the method in the bean executeString method
- The combination of
cron + generator + method
forms a unique constraint
GGCE will inspect this table on startup and add active = true
entries to its Spring scheduler.
On any change to NotificationSchedule
the Spring scheduler will be updated, removing the task when deleted or active = false
, and adjusting the cron
if active = true
. This can be done in the update/create
methods in the NotificationScheduleServiceImpl
.
The API controller is at /api/v2/admin/schedule and follows FilteredCRUDService2Impl
(with DTO, etc).
The API needs to be able to inform the UI which methods are available for scheduling. A new annotation @ScheduledNotification
is added to KPINotifications
and this annotation determines which methods can be included in the custom schedule.
@ScheduledNotification(value = "sendAllKPIs")
@Transactional(readOnly = true)
public void generateLastKPIExecutions() {
for (var execution : executionRepository.listActiveExecutions()) {
notifyLastKPIExecution(execution.getName())
}
}
We convert from @Scheduled
to a new NotificationSchedule
record in ApplicationStartup
using a programmable liquibase change.
UI
In GGCE Web Admin tools a new section (menu) Scheduler is added. It allows the Adminstrator to manage NotificationSchedule
records.
Multiple schedules can exist for the same @ScheduledNotification
: for example one that runs on Mondays, and one on Fridays.