51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""Jadwal klaim reward BP harian: jalankan `claim.step()` terus-menerus.
|
|
|
|
Menunggu hingga jendela klaim (dihitung `claim.py` dari `last_claim_time` +
|
|
24 jam), lalu `step()` menangani resume fee → jadwal → poll `claimrewards`
|
|
tiap `CLAIM_RETRY_SECONDS`. Loop tak pernah keluar — service dijaga hidup oleh
|
|
restart_policy swarm; restart aman karena fee yang belum terkirim dilanjutkan
|
|
dari `claim_runs` (V34). `TZ` env menentukan waktu lokal via `datetime.now()`
|
|
(libc); image Dockerfile.claim sudah menyertakan tzdata.
|
|
|
|
Berbeda dgn scan: ⊥ ada klaim-awal saat start — klaim dgn key salah / jendela
|
|
belum buka hanya dicatat lalu dicoba lagi (⊥ menabrak rule 24 jam).
|
|
|
|
Scheduler helper (`_wait_db`) sengaja diduplikasi dari `scan_loop.py` (bukan
|
|
di-import) karena image Docker terpisah — `Dockerfile.claim` membawa
|
|
`config.py db.py telegram.py distribute.py claim.py claim_loop.py` saja.
|
|
"""
|
|
|
|
import time
|
|
|
|
import db
|
|
import claim
|
|
|
|
|
|
def _wait_db(timeout=120):
|
|
"""Tunggu basis data siap (mariadb baru boot) sebelum loop."""
|
|
start = time.monotonic()
|
|
while time.monotonic() - start < timeout:
|
|
try:
|
|
db.queryone('SELECT 1')
|
|
return
|
|
except Exception:
|
|
time.sleep(3)
|
|
raise RuntimeError('basis data tak siap setelah menunggu')
|
|
|
|
|
|
def main():
|
|
from config import CLAIM_RETRY_SECONDS
|
|
print(f'Jadwal klaim reward BP: poll tiap {CLAIM_RETRY_SECONDS}s '
|
|
f'di jendela klaim (last_claim_time + 24 jam)', flush=True)
|
|
_wait_db()
|
|
while True:
|
|
try:
|
|
claim.step()
|
|
except Exception as exc:
|
|
print(f'[Error] Siklus klaim gagal: {exc}', flush=True)
|
|
time.sleep(CLAIM_RETRY_SECONDS)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|