[ZILANT] debug 2 - test reg script
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2026-08-02 15:50:44 +03:00
parent 72c7d38609
commit 2797183834
3 changed files with 102 additions and 18 deletions
+27 -5
View File
@@ -1,10 +1,32 @@
from tg_mainbot import app
import fcntl
import hashlib
import os
# Регистрация webhook — в gunicorn_bot.conf.py (on_starting), один раз в master.
# Здесь только WSGI-приложение для воркеров.
from tg_mainbot import WEBHOOK_SECRET, WEBHOOK_URL, app, setup_webhook
def _ensure_webhook():
"""
Один раз на старте gunicorn регистрируем webhook с secret_token.
Блокирующий flock — без гонки 4 воркеров и без 429.
"""
digest = hashlib.sha256(
f"{WEBHOOK_URL}|{WEBHOOK_SECRET or ''}".encode("utf-8")
).hexdigest()[:16]
marker_path = f"/tmp/zilant_webhook_ok_{digest}"
lock_path = "/tmp/zilant_webhook_setup.lock"
with open(lock_path, "w") as lock_file:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX)
if os.path.exists(marker_path):
return
setup_webhook()
with open(marker_path, "w") as marker:
marker.write("ok\n")
_ensure_webhook()
if __name__ == "__main__":
from tg_mainbot import setup_webhook
setup_webhook()
app.run()