# Celery Schedule - Daily Task Execution This document outlines the scheduled tasks in the DAS system organized by hour of the day. ## Hour-by-Hour Schedule ### 12:00 AM (00:00) - **set_alert_counter_for_all_users** - Resets alert counter for all users - Task: `activity.tasks.reset_alert_counter_for_all_users` - Schedule: Daily at midnight ### 2:00 AM - **download-features-from-wfs** - Downloads features from Web Feature Service - Task: `mapping.tasks.automate_download_features_from_wfs` - Schedule: Daily at 2:00 AM ### 3:00 AM - **reconcile-observation-segments** - Daily safety net that detects and rebuilds `ObservationSegment` gaps in the recent window for each tenant. Walks every source with activity in the last `OBSERVATION_SEGMENT_RECONCILE_HOURS` hours; runs `recompute_observation_segments_for_source_range` (idempotent via `select_for_update` + `IntegrityError` fallback) when the segment count diverges from `count(valid_obs) - 1`. Closes the gap left by paths that bypass `post_save` (notably bulk updates on `exclusion_flags`). - Task: `observations.tasks.reconcile_observation_segments_task` - Schedule: Daily at 3:00 AM (tenant-local, ahead of the 4:00 AM cleanup run) - Queue: `maintenance` - Options: `expires=20h` so stale per-tenant messages drop before the next run if workers fall behind. ### 4:00 AM - **routine-delete-observational-data** - Maintains observation data (cleanup) - Task: `observations.tasks.maintain_observation_data` - Schedule: Daily at 4:00 AM ### 6:00 AM - **reports** - Generates subject/source reports - Task: `reports.tasks.subjectsource_report` - Schedule: Daily at 6:00 AM ### Every Hour - **check-sources-threshold** - Checks sources threshold - Task: `reports.tasks.run_check_sources_threshold` - Schedule: Every hour - **refresh_tenants_cache** - Refreshes tenants cache - Task: `das_server.tasks.refresh_tenants_cache` - Schedule: Every hour ### Every 15 Minutes - **firms-plugins** - Schedules FIRMS plugins - Task: `tracking.tasks.schedule_firms_plugins` - Schedule: Every 15 minutes - **poll_news_gcs_bucket** - Polls news GCS bucket - Task: `observations.tasks.poll_news_gcs_bucket` - Schedule: Every 15 minutes ### Every 10 Minutes - **sweep-orphan-socketio-queues** - Deletes orphan `python-socketio.*` queue keys left in the realtime broker Redis when a socketio consumer terminates abnormally. Removes keys idle for more than 24h and the matching entry in the `_kombu.binding.socketio` registry. - Task: `rt_api.tasks.sweep_orphan_socketio_queues` - Schedule: Every 10 minutes - Queue: `maintenance` ### Every 5 Minutes - **plugins** - Runs tracking plugins - Task: `tracking.tasks.run_plugins` - Schedule: Every 5 minutes - **auto-resolve** - Automatically updates event state - Task: `activity.tasks.automatically_update_event_state` - Schedule: Every 5 minutes ### Every 30 Minutes - **observation-lag-report** - Reports on observation lag delays - Task: `reports.tasks.alert_lag_delay` - Schedule: Every 30 minutes ### Every Minute - **periodically_maintain_patrol_state** - Maintains patrol state - Task: `activity.tasks.periodically_maintain_patrol_state` - Schedule: Every minute ### Every 60 Seconds - **beat-pulse** - Celery beat pulse routine - Task: `das_server.tasks.celerybeat_pulse` - Schedule: Every 60 seconds ### Every 15 Seconds - **service-status** - Broadcasts service status - Task: `rt_api.tasks.broadcast_service_status` - Schedule: Every 15 seconds ### Every 60 Seconds - **redis-status** - Checks Redis queues - Task: `rt_api.tasks.check_redis_queues` - Schedule: Every 60 seconds ### Every 12 Hours - **subject-status-maintenance** - Maintains subject status for all subjects - Task: `observations.tasks.maintain_subjectstatus_all` - Schedule: Every 12 hours ### Weekly (Sunday at 11:00 PM) - **postgresql_partman_maintain_observation_partitions** - Creates the missing monthly partitions of each partman-managed observations table (`observations_observation`, `observations_observationsegment`) in turn, for the current UTC month through `premake` months ahead, with `partman.create_partition_time`. A failure on one table or month is logged and does not stop the others. - Task: `observations.tasks.maintain_observation_partitions` - Schedule: Every Sunday at 11:00 PM (finishes before the Monday midnight check) - Runs once per database, not per tenant: every tenant's rows share these tables and pg_partman config is per table. - Applies no retention. The `'3 years'` retention in `partman.part_config` for `observations_observationsegment` (set by migration `observations/0200`) is not enforced by this job and would need its own explicit job. ### Weekly (Monday at 12:00 AM) - **postgresql_partman_check_observation_partitions** - Runs the partition table check (premake >= 3, and a partition present for every month from the current UTC month through `premake - 1` months ahead) on `observations_observation` and `observations_observationsegment`. A missing month whose rows are already in the default partition also gets the `fix_partition_by_month` hint described below. - Task: `observations.tasks.check_observation_partitions` - Schedule: Every Monday at midnight ## Queue Priorities The system uses different queues to manage task priorities: - **realtime_p1**: High-priority real-time tasks - **realtime_p2**: Medium-priority real-time tasks - **realtime_p3**: Lower-priority real-time tasks - **maintenance**: System maintenance tasks - **analyzers**: Analysis and processing tasks ## Notes - All times are based on the system's configured timezone (`settings.TIME_ZONE`) - Tasks with `timedelta` schedules run continuously at the specified intervals - Tasks with `crontab` schedules run at specific times on specific days - The `PLUGINS_INTERVAL` is set to 5 minutes (300 seconds) for plugin execution - High-frequency tasks like service status and Redis checks ensure system health monitoring - **Partition maintenance:** `maintain_observation_partitions` never calls `partman.run_maintenance()` or `run_maintenance_proc()`. In pg_partman 5, `run_maintenance` anchors on the newest child partition that holds rows and ignores `now()` (with `infinite_time_partitions = false`) and the default partition. One far-future row in a child therefore makes it create every month up to that date plus `premake` in a single run, and rows landing in the default partition freeze it. Instead, for each table the job reads `control`, `premake` and `partition_interval` from `partman.part_config`. It skips the table, with an `ER Partman:` error, if the table is not registered or the interval is not exactly one month. Its target window runs from the current UTC month through `premake` months ahead, which covers every month the Monday check expects. The check deliberately expects one month fewer than the job creates: it runs an hour after the job, so when the 1st is a Monday it runs in the next month, and expecting `premake + 1` months would then demand a month the job had no reason to create yet, and the months missing from the existing partition boundaries are the ones to create. Each missing month not blocked by default-partition rows (see below) is created with `partman.create_partition_time` and an explicit UTC month start (`'2026-11-01 00:00:00+00'`), one month per transaction with `lock_timeout = 5s`, `statement_timeout = 60s` and `TimeZone = UTC` set locally. One month failing does not undo or stop the others. A monthly maintenance task with no timeouts was removed in December 2024 after it brought down the API (ERA-10622): attaching a partition takes an ACCESS EXCLUSIVE lock on the default partition and scans it, so a lock request stuck behind a long-running query queues all later queries on the table. A month that hits a timeout logs `ER Partman: [