throttle polling outside business hours

Single DAG, single 30-min schedule instead of 5-min or two separate
DAGs. run_sync() itself decides whether to do real work: always during
business hours (default 07:00-17:00 WIB), otherwise only once per
EDOXID_OFF_HOURS_INTERVAL_MINUTES (default 120) tracked via a
last_full_sync timestamp in the sqlite state. Off-hours skips return
immediately without touching DB/Calendar/Gmail at all.
This commit is contained in:
Power BI Dev
2026-07-27 22:33:04 +07:00
parent 7a6dc7d9ae
commit a357e0622e
5 changed files with 90 additions and 9 deletions
+17
View File
@@ -25,6 +25,23 @@ class StateStore:
)
"""
)
self._conn.execute(
"CREATE TABLE IF NOT EXISTS sync_meta (key TEXT PRIMARY KEY, value TEXT NOT NULL)"
)
self._conn.commit()
def get_last_full_sync(self) -> datetime | None:
row = self._conn.execute(
"SELECT value FROM sync_meta WHERE key = 'last_full_sync'"
).fetchone()
return datetime.fromisoformat(row[0]) if row else None
def set_last_full_sync(self, when: datetime) -> None:
self._conn.execute(
"INSERT INTO sync_meta (key, value) VALUES ('last_full_sync', ?) "
"ON CONFLICT(key) DO UPDATE SET value = excluded.value",
(when.isoformat(),),
)
self._conn.commit()
def close(self) -> None: