-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathworker.py
More file actions
55 lines (40 loc) · 1.43 KB
/
Copy pathworker.py
File metadata and controls
55 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
worker.py — Standalone event-queue consumer.
TODAY (Render free tier): NOT deployed. The web process runs the same
consumers in-process via server._boot() because free tier has no worker dyno.
FUTURE (paid tier / higher load): deploy this as a Render "worker" service and
set EVENT_QUEUE_CONSUMERS=0 on the web service. Zero code changes anywhere
else — producer, envelope format, and recovery logic are shared via
app/core/event_queue.py.
startCommand: python worker.py
Env: same as web service (REDIS_URL, GITHUB_*, GROQ_API_KEY, ...).
"""
import logging
import os
import signal
import sys
import time
logging.basicConfig(
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
level=logging.INFO,
)
log = logging.getLogger("worker")
def run() -> None:
from app.core.event_queue import start_consumers, stop_consumers
from app.core.webhook_security import startup_check
from server import _run_handler
startup_check()
started = start_consumers(_run_handler)
if not started:
log.error("worker.no_consumers — Redis unavailable or EVENT_QUEUE_CONSUMERS=0")
sys.exit(1)
def _sigterm(signum, frame):
log.info("worker.sigterm — draining")
stop_consumers()
sys.exit(0)
signal.signal(signal.SIGTERM, _sigterm)
log.info(f"worker.running consumers={started} pid={os.getpid()}")
while True:
time.sleep(60)
if __name__ == "__main__":
run()