allow setting ttl in protonmsg

This commit is contained in:
Mike McLean 2024-11-05 14:01:27 -05:00 committed by Tomas Kopecek
parent fa0c558912
commit 8a472ed94e
3 changed files with 7 additions and 1 deletions

View file

@ -224,12 +224,12 @@ The following fields are understood:
before timing out before timing out
The ``[message]`` section sets parameters for how messages are formed. 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 * ``extra_limit`` -- the maximum allowed size for ``build.extra`` fields that
appear in messages. If the ``build.extra`` field is longer (in terms of 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`` json-encoded length), then it will be omitted. The default value is ``0``
which means no limit. 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 The ``[queue]`` section controls how (or if) the plugin will use the database
to queue messages when they cannot be immediately sent. to queue messages when they cannot be immediately sent.

View file

@ -11,6 +11,8 @@ send_timeout = 60
# if field is longer (json.dumps), ignore it # if field is longer (json.dumps), ignore it
# default value is 0 - unlimited size # default value is 0 - unlimited size
extra_limit = 0 extra_limit = 0
# message ttl can be specified in seconds, default is no ttl
# ttl = 86400
[queue] [queue]
# enable persistent database queue # enable persistent database queue

View file

@ -93,6 +93,7 @@ class TimeoutHandler(MessagingHandler):
return 'topic://' + koji_topic_prefix return 'topic://' + koji_topic_prefix
def send_msgs(self, event): def send_msgs(self, event):
ttl = self.conf.getfloat('message', 'ttl', fallback=None)
for msg in self.msgs: for msg in self.msgs:
# address is like "topic://koji.package.add" # address is like "topic://koji.package.add"
address = self.topic_prefix + '.' + msg['address'] address = self.topic_prefix + '.' + msg['address']
@ -104,6 +105,9 @@ class TimeoutHandler(MessagingHandler):
self.log.debug('created new sender for %s', address) self.log.debug('created new sender for %s', address)
self.senders[address] = sender self.senders[address] = sender
pmsg = Message(properties=msg['props'], body=msg['body']) 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) delivery = sender.send(pmsg)
self.log.debug('sent message: %s', msg['props']) self.log.debug('sent message: %s', msg['props'])
self.pending[delivery] = msg self.pending[delivery] = msg