distribusi: notifikasi Telegram mulai/selesai/gagal (telegram.py, V30)

This commit is contained in:
proitlab committed 2026-08-06 05:30:22 +07:00
1 parent 397e20ec3a
commit 025f46d399
8 files changed
+170 -7

No files matched your search

+11 -1
View File
@@ -19,6 +19,7 @@ from decimal import Decimal, ROUND_FLOOR, InvalidOperation
import requests
import db
import telegram
from config import (API_NODE, BP_PRIVATE_KEY, DATABISNIS_API,
DISTRIBUTE_MAX_ATTEMPTS, TARGET_BP, TOKEN_CONTRACT,
VEX_SYMBOL)
@@ -154,6 +155,9 @@ def run_distribution(dry_run=False):
'VEX_BP_PRIVATE_KEY kosong — set secret dulu sebelum run nyata '
'(⊥ distribusi tanpa key)')
total_share = sum(share for _, share in shares)
telegram.notify_start(run_date, len(shares), total_share, balance)
created_at = datetime.now().isoformat(timespec='seconds')
total_stake = sum(float(s) for _, s in voters)
run_id = db.record_run(run_date, float(balance), len(voters), total_stake,
@@ -206,6 +210,8 @@ def run_distribution(dry_run=False):
status = 'ok' if not failed else 'partial'
db.update_run_status(run_id, status, round(sent_amount, 4))
telegram.notify_finish(status, len(pending) - len(failed), len(pending),
total_share, failed, run_date)
print(f'SELESAI: {len(pending) - len(failed)}/{len(pending)} terkirim '
f'(status run: {status})', flush=True)
return 0
@@ -213,7 +219,11 @@ def run_distribution(dry_run=False):
def main():
dry_run = '--dry-run' in sys.argv
return run_distribution(dry_run=dry_run)
try:
return run_distribution(dry_run=dry_run)
except Exception as exc:
telegram.notify_failure(exc)
raise
if __name__ == '__main__':