This commit is contained in:
2026-02-13 15:50:56 +02:00
parent 0fe60b95f8
commit 4578d443a2

View File

@@ -42,7 +42,7 @@ NB_TOKEN = "7648e4f5ee370cda7834682e61b47c2ee8e95623" # keep as provided
NB_TIMEOUT = 3.0 # seconds per HTTP GET NB_TIMEOUT = 3.0 # seconds per HTTP GET
# ========================= # =========================
# RabbitMQ hardcoded config (immediate publish like rmq-ikeja-pub3.sh without delay) # RabbitMQ hardcoded config
# ========================= # =========================
RMQ_HOST = "10.210.12.2" RMQ_HOST = "10.210.12.2"
RMQ_PORT = 15672 RMQ_PORT = 15672
@@ -50,9 +50,14 @@ RMQ_USER = "admin"
RMQ_PASS = "change_me" RMQ_PASS = "change_me"
RMQ_VHOST = "app" RMQ_VHOST = "app"
RMQ_EXCHANGE_WORK = "deviceconfig" # direct exchange (immediate) RMQ_EXCHANGE_WORK = "deviceconfig" # direct exchange (immediate)
RMQ_EXCHANGE_DELAYED = "deviceconfig.delayed" # delayed exchange (x-delayed-message)
RMQ_ROUTING_KEY = "deviceconfig" RMQ_ROUTING_KEY = "deviceconfig"
RMQ_TIMEOUT = 3.0 RMQ_TIMEOUT = 3.0
# ---- Human-editable delay (milliseconds). Set to 0 to disable delay.
# Example: 600000 = 10 minutes
RMQ_DELAY_MS = 0
# Product -> Tag slug mapping (kept unchanged, though not used now) # Product -> Tag slug mapping (kept unchanged, though not used now)
PRODUCT_TAG_SLUG = { PRODUCT_TAG_SLUG = {
"fox100": "fox100-auto-upgrade-latest", "fox100": "fox100-auto-upgrade-latest",
@@ -461,7 +466,8 @@ async def main():
) )
else: else:
# Publish task_name=action_next # Publish task_name=action_next
rmq_url = f"http://{RMQ_HOST}:{RMQ_PORT}/api/exchanges/{RMQ_VHOST}/{RMQ_EXCHANGE_WORK}/publish" target_exchange = RMQ_EXCHANGE_DELAYED if RMQ_DELAY_MS > 0 else RMQ_EXCHANGE_WORK
rmq_url = f"http://{RMQ_HOST}:{RMQ_PORT}/api/exchanges/{RMQ_VHOST}/{target_exchange}/publish"
payload_obj = { payload_obj = {
"inscope_device": host, "inscope_device": host,
@@ -479,6 +485,9 @@ async def main():
"payload_encoding": "string", "payload_encoding": "string",
} }
if RMQ_DELAY_MS > 0:
rmq_body["properties"]["headers"] = {"x-delay": int(RMQ_DELAY_MS)}
await log_status( await log_status(
f"[{ts()}] ok, here i will execute\n" f"[{ts()}] ok, here i will execute\n"
f" url: {rmq_url}\n" f" url: {rmq_url}\n"
@@ -521,7 +530,8 @@ async def main():
bell_prefix = "\a" * 3 bell_prefix = "\a" * 3
else: else:
# action_last != action_next -> publish immediately # action_last != action_next -> publish immediately
rmq_url = f"http://{RMQ_HOST}:{RMQ_PORT}/api/exchanges/{RMQ_VHOST}/{RMQ_EXCHANGE_WORK}/publish" target_exchange = RMQ_EXCHANGE_DELAYED if RMQ_DELAY_MS > 0 else RMQ_EXCHANGE_WORK
rmq_url = f"http://{RMQ_HOST}:{RMQ_PORT}/api/exchanges/{RMQ_VHOST}/{target_exchange}/publish"
payload_obj = { payload_obj = {
"inscope_device": host, "inscope_device": host,
@@ -539,6 +549,9 @@ async def main():
"payload_encoding": "string", "payload_encoding": "string",
} }
if RMQ_DELAY_MS > 0:
rmq_body["properties"]["headers"] = {"x-delay": int(RMQ_DELAY_MS)}
await log_status( await log_status(
f"[{ts()}] ok, here i will execute\n" f"[{ts()}] ok, here i will execute\n"
f" url: {rmq_url}\n" f" url: {rmq_url}\n"