Skip to content

Send a reminder when something sits too long

Declare an Event with a schedule, and keep the schedule to the state the Item waits in. When the schedule is due, the Runtime publishes the Event once for each Item in that state. A Listener on the Event sends the reminder.

In the leave App, a request waits in pending until a manager decides:

leave.ts
const reminderDue = leaveRequest.addEvent('reminderDue');
reminderDue.addSchedule('weekdays', '0 9 * * 1-5').state(['pending']);
reminderDue.addListener('remind', async (_event, item) => {
await item.updateProperties({ notice: 'Waiting for a decision' });
});

0 9 * * 1-5 is a crontab: 9:00, Monday to Friday. state(['pending']) keeps the schedule to pending requests. remind saves the reminder as a notice on the request, where a real App sends an email or a chat message.

Nobody decides “Wedding”, and “Dentist” is rejected. The clock of the script starts at midnight on a Wednesday, and the script moves it one day:

As Alice: "Wedding" is pending
Clock: Wed, 01 Jan 2020 00:00:00 GMT
As Alice: "Wedding" has no notice
Clock: Thu, 02 Jan 2020 00:00:00 GMT
As Alice: "Wedding" has the notice "Waiting for a decision"
As Alice: "Dentist" has the notice "Rejected: Team offsite"

Look at “Wedding”: it has no notice until the clock has passed 9:00. “Dentist” is not pending, so the schedule skips it and its notice stays as it was.

The schedule does not measure the wait: a request made one minute before 9:00 gets the reminder with the rest. To act on an Item only when its own time is up, save a due time on it and compare the time in the Listener, as Move an item to a new state at a deadline does.

The whole App, built step by step: Tutorial: what happens next.