Files
clientsflow/schedulers/README.md

39 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Client Timeline Calendar Scheduler
Изолированный scheduler-сервис для актуализации `ClientTimelineEntry.datetime` за 30 минут до календарного события.
## Что делает
- Берет advisory lock в PostgreSQL, чтобы не было гонок между инстансами.
- Находит активные `CalendarEvent` с `contactId` в рабочем окне времени.
- Когда событие вошло в окно `start - 30m`, делает upsert в `ClientTimelineEntry`:
- `contentType = CALENDAR_EVENT`
- `datetime = startsAt - TIMELINE_EVENT_PREDUE_MINUTES`
## ENV
- `DATABASE_URL` (обязательно)
- `TIMELINE_EVENT_PREDUE_MINUTES` (default `30`)
- `TIMELINE_EVENT_LOOKBACK_MINUTES` (default `180`)
- `TIMELINE_EVENT_LOOKAHEAD_MINUTES` (default `1440`)
- `TIMELINE_SCHEDULER_LOCK_KEY` (default `603001`)
## Локально
```bash
cd schedulers
npm install
npm run start
```
## Docker
```bash
docker build -t client-timeline-calendar-scheduler .
docker run --rm -e DATABASE_URL="$DATABASE_URL" client-timeline-calendar-scheduler
```
## Dokploy
Сделай отдельный app/job и поставь schedule `* * * * *`.