From 8a472ed94e8740838fc3d432b543f49d6498ac24 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Tue, 5 Nov 2024 14:01:27 -0500 Subject: [PATCH] allow setting ttl in protonmsg --- docs/source/plugins.rst | 2 +- plugins/hub/protonmsg.conf | 2 ++ plugins/hub/protonmsg.py | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/plugins.rst b/docs/source/plugins.rst index 7f27895d..d28a877c 100644 --- a/docs/source/plugins.rst +++ b/docs/source/plugins.rst @@ -224,12 +224,12 @@ The following fields are understood: before timing out The ``[message]`` section sets parameters for how messages are formed. -Currently only one field is understood: * ``extra_limit`` -- the maximum allowed size for ``build.extra`` fields that appear in messages. If the ``build.extra`` field is longer (in terms of json-encoded length), then it will be omitted. The default value is ``0`` which means no limit. +* ``ttl`` -- The time to live to set for messages. Measured in seconds The ``[queue]`` section controls how (or if) the plugin will use the database to queue messages when they cannot be immediately sent. diff --git a/plugins/hub/protonmsg.conf b/plugins/hub/protonmsg.conf index 45f43c48..72c1d265 100644 --- a/plugins/hub/protonmsg.conf +++ b/plugins/hub/protonmsg.conf @@ -11,6 +11,8 @@ send_timeout = 60 # if field is longer (json.dumps), ignore it # default value is 0 - unlimited size extra_limit = 0 +# message ttl can be specified in seconds, default is no ttl +# ttl = 86400 [queue] # enable persistent database queue diff --git a/plugins/hub/protonmsg.py b/plugins/hub/protonmsg.py index c28aa4de..27f13f0e 100644 --- a/plugins/hub/protonmsg.py +++ b/plugins/hub/protonmsg.py @@ -93,6 +93,7 @@ class TimeoutHandler(MessagingHandler): return 'topic://' + koji_topic_prefix def send_msgs(self, event): + ttl = self.conf.getfloat('message', 'ttl', fallback=None) for msg in self.msgs: # address is like "topic://koji.package.add" address = self.topic_prefix + '.' + msg['address'] @@ -104,6 +105,9 @@ class TimeoutHandler(MessagingHandler): self.log.debug('created new sender for %s', address) self.senders[address] = sender pmsg = Message(properties=msg['props'], body=msg['body']) + if ttl: + # The message class expects seconds, even though the c api uses milliseconds + pmsg.ttl = ttl delivery = sender.send(pmsg) self.log.debug('sent message: %s', msg['props']) self.pending[delivery] = msg