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
+14
View File
@@ -56,3 +56,17 @@ def get_sync_min_date() -> str:
yang sudah punya schedule. Ubah lewat env var kalau memang mau backfill sengaja.
"""
return os.environ.get("EDOXID_SYNC_MIN_DATE", "today")
def get_business_hours() -> tuple[int, int]:
"""(jam_mulai, jam_selesai) WIB — di luar rentang ini, sync sungguhan cuma
jalan tiap `get_off_hours_interval_minutes()`, bukan tiap trigger DAG.
Tidak perlu 2 DAG terpisah — DAG tetap 1 jadwal (tiap 30 menit), tapi
run_sync() sendiri yang skip kalau lagi di luar jam kerja & belum waktunya."""
start = int(os.environ.get("EDOXID_BUSINESS_HOURS_START", "7"))
end = int(os.environ.get("EDOXID_BUSINESS_HOURS_END", "17"))
return start, end
def get_off_hours_interval_minutes() -> int:
return int(os.environ.get("EDOXID_OFF_HOURS_INTERVAL_MINUTES", "120"))