jadwal distribusi multi-hari Rabu & Sabtu (V44/T49): DISTRIBUTE_WEEKDAY=wed,sat (CSV), next_boundary pilih hari terdekat, banner BERITA SETIAP RABU & SABTU ; image web+dist rebuild + push

This commit is contained in:
proitlab committed 2026-08-07 15:49:26 +07:00
1 parent bdb5923097
commit a6db3be436
10 files changed
+173 -70

No files matched your search

+41 -24
View File
@@ -1,9 +1,10 @@
"""Jadwal distribusi mingguan: jalankan distribute.py pada hari `DISTRIBUTE_WEEKDAY`
jam `DISTRIBUTE_HOUR`, plus satu one-off `DISTRIBUTE_FIRST_RUN` (YYYY-MM-DD,
default baked `2026-08-17` via config).
"""Jadwal distribusi: jalankan distribute.py pada hari `DISTRIBUTE_WEEKDAY`
(satu atau CSV, mis. `wed,sat`) jam `DISTRIBUTE_HOUR`, plus satu one-off
`DISTRIBUTE_FIRST_RUN` (YYYY-MM-DD, default baked `2026-08-17` via config).
Contoh produksi: `DISTRIBUTE_FIRST_RUN=2026-08-17` (Senin) lalu `DISTRIBUTE_WEEKDAY=sat`
→ putaran pertama Senin 17 Agt 10:00, berikutnya tiap Sabtu 10:00.
Contoh produksi: `DISTRIBUTE_FIRST_RUN=2026-08-17` (Senin) lalu
`DISTRIBUTE_WEEKDAY=wed,sat` → putaran pertama Senin 17 Agt 10:00, berikutnya
tiap Rabu & Sabtu 10:00.
Menunggu hingga batas terjadwal berikutnya (waktu lokal via `TZ`) lalu memanggil
`distribute.main()`. Loop tak pernah keluar — service dijaga hidup oleh
@@ -43,6 +44,17 @@ def parse_weekday(value):
raise ValueError(f'DISTRIBUTE_WEEKDAY tak valid: {value!r}')
def parse_weekdays(value):
"""Satu hari (`sat`) atau CSV beberapa hari (`wed,sat`) → daftar weekday
(int, Senin=0) unik terurut. V44: jadwal bisa multi-hari per minggu."""
if not value:
raise ValueError('DISTRIBUTE_WEEKDAY kosong')
days = sorted({parse_weekday(d) for d in str(value).split(',') if d.strip()})
if not days:
raise ValueError(f'DISTRIBUTE_WEEKDAY tak valid: {value!r}')
return days
def parse_first_run(value):
"""`YYYY-MM-DD` → date; kosong → None (⊥ one-off)."""
if not value:
@@ -50,26 +62,30 @@ def parse_first_run(value):
return datetime.strptime(str(value).strip(), '%Y-%m-%d').date()
def next_boundary(now, hour, weekday, first_run=None):
def next_boundary(now, hour, weekdays, first_run=None):
"""datetime berikutnya utk distribusi.
Mingguan: `weekday` jam `hour`. Bila `first_run` diset, distribusi ⊥ jalan
sebelum tanggal itu — Sabtu (atau hari mingguan) yang jatuh sebelum launch
dilewati; event = {one-off `first_run` (jika masih depan)} ∪ {mingguan ≥
tanggal `first_run`}; pilih yang terdekat > `now`."""
days_ahead = (weekday - now.weekday()) % 7
weekly = (now.replace(hour=hour, minute=0, second=0, microsecond=0)
+ timedelta(days=days_ahead))
if weekly <= now:
weekly += timedelta(days=7)
if first_run is None:
return weekly
start = datetime(first_run.year, first_run.month, first_run.day, hour=hour)
Mingguan: tiap hari di `weekdays` (list int) jam `hour`. Bila `first_run`
diset, distribusi ⊥ jalan sebelum tanggal itu — hari-hari mingguan yang
jatuh sebelum launch dilewati; event = {one-off `first_run` (jika masih
depan)} ∪ {mingguan ≥ tanggal `first_run`}; pilih yang terdekat > `now`."""
if isinstance(weekdays, int):
weekdays = [weekdays]
start = None
if first_run is not None:
start = datetime(first_run.year, first_run.month, first_run.day,
hour=hour)
candidates = []
if start >= now:
if start is not None and start >= now:
candidates.append(start)
if weekly >= start:
candidates.append(weekly)
for weekday in weekdays:
days_ahead = (weekday - now.weekday()) % 7
weekly = (now.replace(hour=hour, minute=0, second=0, microsecond=0)
+ timedelta(days=days_ahead))
if weekly <= now:
weekly += timedelta(days=7)
if start is None or weekly >= start:
candidates.append(weekly)
return min(candidates)
@@ -97,15 +113,16 @@ def main():
hour = config.DISTRIBUTE_HOUR
if not 0 <= hour <= 23:
raise ValueError(f'DISTRIBUTE_HOUR tak valid: {hour!r}')
weekday = parse_weekday(config.DISTRIBUTE_WEEKDAY)
weekdays = parse_weekdays(config.DISTRIBUTE_WEEKDAY)
first_run = parse_first_run(config.DISTRIBUTE_FIRST_RUN)
jadwal = (f'jam {hour} tiap hari {list(WEEKDAYS)[weekday]} (waktu lokal)'
hari = ' & '.join(list(WEEKDAYS)[d] for d in weekdays)
jadwal = (f'jam {hour} tiap hari {hari} (waktu lokal)'
+ (f', one-off {first_run.isoformat()}' if first_run else ''))
print(f'Jadwal distribusi: {jadwal}')
_wait_db()
while True:
now = datetime.now()
target = next_boundary(now, hour, weekday, first_run)
target = next_boundary(now, hour, weekdays, first_run)
wait = (target - now).total_seconds()
print(f'{now.isoformat(timespec="seconds")} tidur {wait / 3600:.2f} jam '
f'sampai {target.isoformat(timespec="seconds")}', flush=True)