Fix milestone sharing and test worker routing
This commit is contained in:
@@ -73,14 +73,15 @@ def render_card(card):
|
||||
start_ms = min(_timestamp(point.get("at")) for point in raw_points)
|
||||
end_ms = max(_timestamp(point.get("at")) for point in raw_points)
|
||||
span = max(1, end_ms - start_ms)
|
||||
ceiling = float(trend.get("ceiling") or max(total * 1.25, 1.25))
|
||||
ceiling = 5.0 if total <= 5 else float(trend.get("ceiling") or total * 1.25)
|
||||
points = [(left + round((_timestamp(point.get("at")) - start_ms) / span * width), top + height - round(float(point.get("total", 0)) / ceiling * height)) for point in raw_points]
|
||||
target_y = top + height - round(float(trend.get("target") or total) / ceiling * height)
|
||||
# Exactly five levels: for 20 scans, 5 / 10 / 15 / 20 / 25.
|
||||
for index in range(1, 6):
|
||||
value = total * index / 4
|
||||
# Small milestones use whole scans (1..5); larger ones keep the
|
||||
# reached milestone on the fourth of five levels.
|
||||
axis_values = list(range(1, 6)) if total <= 5 else [total * index / 4 for index in range(1, 6)]
|
||||
for value in axis_values:
|
||||
y = top + height - round(value / ceiling * height)
|
||||
is_target = index == 4
|
||||
is_target = value == total
|
||||
draw.line((left, y, left + width, y), fill="#bfdbfe" if is_target else "#dde5ef", width=2 if is_target else 1)
|
||||
draw.text((left - 15, y - 12), _format_axis(value), font=font("DejaVuSans.ttf", 18), fill=blue if is_target else slate, anchor="ra")
|
||||
draw.line(points, fill=blue, width=5, joint="curve")
|
||||
@@ -146,6 +147,12 @@ if __name__ == "__main__":
|
||||
interval = max(5, int(os.getenv("SOCIAL_WORKER_INTERVAL_SECONDS", "10")))
|
||||
if os.getenv("SOCIAL_MILESTONE_POSTING_ENABLED", "").lower() not in {"true", "1", "yes"}:
|
||||
raise RuntimeError("Set SOCIAL_MILESTONE_POSTING_ENABLED=true to run this worker")
|
||||
print(json.dumps({"worker": "social-milestones", "status": "started", "intervalSeconds": interval}), flush=True)
|
||||
while True:
|
||||
run_once()
|
||||
try:
|
||||
run_once()
|
||||
except Exception as error:
|
||||
# Stay alive and make configuration/network errors visible in the
|
||||
# container logs instead of entering a silent restart loop.
|
||||
print(f"Worker cycle failed: {error}", flush=True)
|
||||
time.sleep(interval)
|
||||
|
||||
Reference in New Issue
Block a user