
# Set the automatic sends

You set the scheduled job that sends the day-before reminder, the chasers and the alerts, you activate the right edition, and you know in what order to check when "nobody received anything". Four sends share a single job: the day-before reminder, the chaser for staff who have not acknowledged their schedule, the alert on swap requests waiting for a decision, and the chaser of the availability collection.

## 1. Set the rhythm and the time zone

```properties
NOTIFICATIONS_CRON=0 5 * * * ?
NOTIFICATIONS_TIMEZONE=Europe/Paris
```

![The hourly sending of scheduled notifications](repo:docs/diagrammes/notifications-planifiees.svg)

<sub>Source: [`diagrammes/notifications-planifiees.puml`](repo:docs/diagrammes/notifications-planifiees.puml).</sub>

The cron is hourly, on purpose: the reminder's send time is decided **per edition** (*Settings › Notifications*, *Automatic reminders and chasers* card), and a single job cannot leave at four different times for four editions. It therefore wakes up often, and each edition sends when its own time has passed. The time zone is the event's, set apart (`NOTIFICATIONS_TIMEZONE`) and not the container's (`TZ`, see [back up and restore](sauvegarde-et-restauration.md#1-laisser-la-sauvegarde-de-nuit-tourner)): "6 pm" on screen must mean 6 pm for the person reading.

**The reminder's send time is capped at 23:00**, the screen refuses later: the sending window runs from the set time to midnight, after which "tomorrow" would be wrong, and a later time would leave a window shorter than the interval between two runs, the reminder falling between two wake-ups without leaving. If you space `NOTIFICATIONS_CRON` beyond one run per hour, this cap no longer guarantees it.

## 2. Activate the edition that must write

**Nothing leaves except from the active edition** ([ADR 0072](repo:docs/decisions/0072-une-seule-edition-active.md)). The *Editions* page carries the "Activate" gesture; at most one edition is active, none between two events, and every edition is born inactive (creation, duplication, import). **On upgrading to `V118`**, the active edition is: the only armed edition if there was exactly one, otherwise the default edition, otherwise the oldest. The choice is written in the startup log (a Flyway `NOTICE`): check it on the *Editions* page before the first night. The "Action required" banner flags an active edition whose last day has passed, or an inactive edition that starts within the next `EDITIONS_RAPPEL_JOURS` days (7 by default).

## 3. Check when nothing arrives

In the order in which it breaks:

1. **The active edition.** If the event's edition was not activated, nothing leaves and nothing says so: this is the cause of "I received nothing" in nine cases out of ten.
2. **The published plan.** The reminder reads the **published** schedule, never the working plan: nobody is reminded of a timeslot they were not told about.
3. **Records with no address.** They are skipped, counted in "To handle today" on the home screen and named in its feed of alerts and messages: these are the people to notify by hand.
4. **Failed sends.** A reminder or chaser the relay refused leaves a red alert in the home feed, and the person is **not counted as chased**: they stay "send failure" on the Staff page. The night does not retry (a relay down at 7 pm is often down at 8 pm); "Chase now" stays open for them once the relay is back, and two simultaneous clicks write once. Only exception: a refused address, whose chaser resumes at the run that follows the correction of the record ([the failure categories](courriels.md#4-lire-ce-qui-est-gardé-de-chaque-envoi)).

## 4. The availability collection chaser

It is switched on with the collection window (*Settings › Edition*, *Desks* card), **off by default**, including on a collection already open before the upgrade. On, it writes once to each **invited** staff member with **no declaration at all**, with the link to "My availabilities" in their espace ([the organiser's guide](../regles/collecter-disponibilites.md)).

| Rule | Why |
| --- | --- |
| Invited = an invitation to declare **sent** (`envoi_mail`, template `invitation-declaration`, state `ENVOYE`) | It is the only trace of the invitation; a failed invitation taught the person nothing. Beyond `JOURNAL_RETENTION`, the row is purged and the person no longer counts as invited |
| No declaration = none, whatever its status | An applied or refused declaration is an answer |
| At the first run at 9 am or later (`NOTIFICATIONS_TIMEZONE`) of a day when the end is in 0 to 3 days | A midnight e-mail is read by nobody. With the shipped hourly cron, it is the 9:05 run; a `NOTIFICATIONS_CRON` that never runs at 9 or after (once a night) **sends no chaser**. A day with no run is caught up the next day, until the last day of the collection |
| Once per person and per end date (key `animateur\|fin`) | Moving the end is a new deadline: a new chaser becomes possible |
| Nothing without an end date, with a closed collection or an inactive edition | No deadline to remind, nobody to answer, or not the current event ([ADR 0072](repo:docs/decisions/0072-une-seule-edition-active.md)) |

A failed send is not retried every hour: each day reserves its attempt (key `animateur|fin|jour`), but the failure gives the deadline's reservation back, so the next day's 9 am run retries, until the last day of the collection, with one red alert per deadline in the home feed. An address refused by the mail server is no longer tried until the record is edited, a record with no address is not tried at all: each case leaves a warning, once per deadline, which designates the record without naming it. Every send is recorded in `envoi_mail` under the `relance-collecte` template.
