INNER CODE UNIT · Python

_publish_and_record

bunkeriot/BunkerM · backend/app/agent-api/main.py:336

def _publish_and_record(topic: str, payload: str, qos: int, retain: bool, job_id: str):
    try:
        mqtt_publish.single(
            topic=topic, payload=payload, qos=qos, retain=retain,
            hostname=MQTT_HOST, port=MQTT_PORT,
            auth={"username": MQTT_USER, "password": MQTT_PASS},
        )
        logger.info(f"Scheduler job {job_id} fired: {topic} = {payload[:60]}")
        with _lock:
            data = _load_agents()
            for j in data["jobs"]:
                if j["id"] == job_id:
                    j["fire_count"] = j.get("fire_count", 0) + 1
                    j["last_fired_at"] = _now()
            _save_agents(data)
    except Exception as e:
        logger.warning(f"Scheduler job {job_id} publish failed: {e}")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…