From 4578d443a2d216eafde1758670448d3bf750716b Mon Sep 17 00:00:00 2001 From: pavel Date: Fri, 13 Feb 2026 15:50:56 +0200 Subject: [PATCH] 1550 --- files/nats_registration_listener.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/files/nats_registration_listener.py b/files/nats_registration_listener.py index abcd7f6..973bf85 100644 --- a/files/nats_registration_listener.py +++ b/files/nats_registration_listener.py @@ -42,17 +42,22 @@ NB_TOKEN = "7648e4f5ee370cda7834682e61b47c2ee8e95623" # keep as provided 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_PORT = 15672 RMQ_USER = "admin" RMQ_PASS = "change_me" 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_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 = { "fox100": "fox100-auto-upgrade-latest", @@ -461,7 +466,8 @@ async def main(): ) else: # 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 = { "inscope_device": host, @@ -479,6 +485,9 @@ async def main(): "payload_encoding": "string", } + if RMQ_DELAY_MS > 0: + rmq_body["properties"]["headers"] = {"x-delay": int(RMQ_DELAY_MS)} + await log_status( f"[{ts()}] ok, here i will execute\n" f" url: {rmq_url}\n" @@ -521,7 +530,8 @@ async def main(): bell_prefix = "\a" * 3 else: # 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 = { "inscope_device": host, @@ -539,6 +549,9 @@ async def main(): "payload_encoding": "string", } + if RMQ_DELAY_MS > 0: + rmq_body["properties"]["headers"] = {"x-delay": int(RMQ_DELAY_MS)} + await log_status( f"[{ts()}] ok, here i will execute\n" f" url: {rmq_url}\n"