diff options
author | Matthew Treinish <mtreinish@kortar.org> | 2016-09-29 18:48:48 -0400 |
---|---|---|
committer | Matthew Treinish <mtreinish@kortar.org> | 2016-09-29 18:51:41 -0400 |
commit | 5ab09429a170a52f13ddb07a17251a13db216949 (patch) | |
tree | 5c78df6f33d583813a51233bc27187a3d8741ced | |
parent | f3911397912641df15b10e4c45aedf7f5b51cb45 (diff) |
Add config option to set the imap idle timeout
This commit adds a new config option to the imap section, idle-timeout,
which is used to set the timeout duration for the idle call. By default
imaplib2 sets this to 29mins. This if far too long especially on an imap
server that doesn't have imap idle configured properly. What ends up
happening is that all the lp events get bunched together and pushed to
mqtt at once every 29mins. This isn't really useful as an event stream.
So this makes it configurable and decreases the default setting to 1 min
which seems like a much more useful default value, albeit at the cost of
more imap traffic to fetch messages.
Change-Id: I98fc9778f0adc548d28e7bbd8600f05ff4946ba2
Notes
Notes (review):
Code-Review+2: Clark Boylan <cboylan@sapwetik.org>
Workflow+1: Matthew Treinish <mtreinish@kortar.org>
Verified+2: Jenkins
Submitted-by: Jenkins
Submitted-at: Wed, 21 Dec 2016 17:48:22 +0000
Reviewed-on: https://review.openstack.org/379849
Project: openstack-infra/lpmqtt
Branch: refs/heads/master
-rw-r--r-- | README.rst | 1 | ||||
-rw-r--r-- | lpmqtt/daemon.py | 6 |
2 files changed, 6 insertions, 1 deletions
@@ -51,6 +51,7 @@ configuration of the imap server you're connecting to: | |||
51 | * **delete-old** - Set this to *True* to have lpmqtt delete messages after it | 51 | * **delete-old** - Set this to *True* to have lpmqtt delete messages after it |
52 | finishes processing them. By default it will just mark them | 52 | finishes processing them. By default it will just mark them |
53 | as read. | 53 | as read. |
54 | * **idle-timeout** - The number of seconds to use for the idle timeout | ||
54 | 55 | ||
55 | MQTT | 56 | MQTT |
56 | ---- | 57 | ---- |
diff --git a/lpmqtt/daemon.py b/lpmqtt/daemon.py index f009da0..304c956 100644 --- a/lpmqtt/daemon.py +++ b/lpmqtt/daemon.py | |||
@@ -111,6 +111,10 @@ def main(): | |||
111 | imap_delete = config.getboolean('imap', 'delete-old') | 111 | imap_delete = config.getboolean('imap', 'delete-old') |
112 | else: | 112 | else: |
113 | imap_delete = False | 113 | imap_delete = False |
114 | if config.has_option('imap', 'imap-timeout'): | ||
115 | imap_idle_timeout = config.getint('imap', 'idle-timeout') | ||
116 | else: | ||
117 | imap_idle_timeout = 60 | ||
114 | 118 | ||
115 | launchpad = lp.LPImapWatcher(imap_server, imap_user, imap_password, | 119 | launchpad = lp.LPImapWatcher(imap_server, imap_user, imap_password, |
116 | folder=imap_folder, ssl=imap_ssl, | 120 | folder=imap_folder, ssl=imap_ssl, |
@@ -120,7 +124,7 @@ def main(): | |||
120 | for event in events: | 124 | for event in events: |
121 | msg, topic = process_event(event, base_topic) | 125 | msg, topic = process_event(event, base_topic) |
122 | mqttqueue.publish_single(topic, msg) | 126 | mqttqueue.publish_single(topic, msg) |
123 | launchpad.imap.idle() | 127 | launchpad.imap.idle(timeout=imap_idle_timeout) |
124 | 128 | ||
125 | if __name__ == "__main__": | 129 | if __name__ == "__main__": |
126 | main() | 130 | main() |