[FIX] bus: compatibility with Odoo's PAAS external long polling handler

Only start the bus events dispatcher when needed (lazy starting).
On Odoo PAAS it's never started because the platform has its own event
dispatcher.
This commit is contained in:
Fabien Meghazi
2017-09-13 09:48:19 +02:00
parent aea183212e
commit a2ed3d3d5b
+10 -4
View File
@@ -108,6 +108,7 @@ class ImBus(models.Model):
class ImDispatch(object):
def __init__(self):
self.channels = {}
self.started = False
def poll(self, dbname, channels, last, options=None, timeout=TIMEOUT):
if options is None:
@@ -129,6 +130,10 @@ class ImDispatch(object):
notifications = env['bus.bus'].poll(channels, last, options)
# or wait for future ones
if not notifications:
if not self.started:
# Lazy start of events listener
self.start()
event = self.Event()
for channel in channels:
self.channels.setdefault(hashable(channel), []).append(event)
@@ -178,15 +183,16 @@ class ImDispatch(object):
import gevent
self.Event = gevent.event.Event
gevent.spawn(self.run)
elif odoo.multi_process:
# disabled in prefork mode
return
else:
# threaded mode
self.Event = threading.Event
t = threading.Thread(name="%s.Bus" % __name__, target=self.run)
t.daemon = True
t.start()
self.started = True
return self
dispatch = ImDispatch().start()
dispatch = None
if not odoo.multi_process or odoo.evented:
# We only use the event dispatcher in threaded and gevent mode
dispatch = ImDispatch()