Skip to content

Commit

Permalink
[MIG] bus_alt_connection: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ioans73 committed Mar 4, 2024
1 parent 045f128 commit f9a0b7c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bus_alt_connection/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Bus Alt Connection
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ae42d6115a36e236c9020c64527f0e9c64d8ac2cae99ed2822ba96b71544d85c
!! source digest: sha256:ab7e1b9d5721f8cb27f93c58ed77e5034bc0099105ac6d5097f1bdc74a4e6973
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion bus_alt_connection/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Bus Alt Connection",
"summary": "Needed when using PgBouncer as a connection pooler",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Trobz,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools",
"category": "Extra Tools",
Expand Down
44 changes: 18 additions & 26 deletions bus_alt_connection/models/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import json
import logging
import os
import select
import selectors

import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT

import odoo
from odoo.tools import config

import odoo.addons.bus.models.bus
from odoo.addons.bus.models.bus import TIMEOUT, hashable
from odoo.addons.bus.models.bus import TIMEOUT, hashable, stop_event

_logger = logging.getLogger(__name__)

Expand All @@ -25,10 +24,8 @@ def _connection_info_for(db_name):
cfg = os.environ.get("ODOO_IMDISPATCHER_DB_%s" % p.upper()) or config.get(
"imdispatcher_db_" + p
)

if cfg:
connection_info[p] = cfg

return connection_info


Expand All @@ -42,34 +39,29 @@ def loop(self):
connection_info,
)
conn = psycopg2.connect(**connection_info)
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
with conn.cursor() as cr:
with conn.cursor() as cr, selectors.DefaultSelector() as sel:
cr.execute("listen imbus")
conn.commit()
while True:
if select.select([conn], [], [], TIMEOUT) == ([], [], []):
pass
else:
sel.register(conn, selectors.EVENT_READ)
while not stop_event.is_set():
if sel.select(TIMEOUT):
conn.poll()
channels = []
while conn.notifies:
channels.extend(json.loads(conn.notifies.pop().payload))
# dispatch to local threads/greenlets
events = set()
# relay notifications to websockets that have
# subscribed to the corresponding channels.
websockets = set()
for channel in channels:
events.update(self.channels.pop(hashable(channel), set()))
for event in events:
event.set()
websockets.update(
self._channels_to_ws.get(hashable(channel), [])
)
for websocket in websockets:
websocket.trigger_notification_dispatching()


odoo.addons.bus.models.bus.ImDispatch = ImDispatch

# we can replace the existing dispatcher because its thread
# has not been started yet; indeed, since a2ed3d it only starts
# on first /poll request:
# https://github.com/odoo/odoo/commit/a2ed3d3d5bdb6025a1ba14ad557a115a86413e65

if not odoo.multi_process or odoo.evented:
dispatch = ImDispatch()
odoo.addons.bus.models.bus.dispatch = dispatch
odoo.addons.bus.controllers.main.dispatch = dispatch
dispatch = ImDispatch()
odoo.addons.bus.models.bus.dispatch = dispatch
odoo.addons.bus.models.ir_websocket.dispatch = dispatch
odoo.addons.bus.websocket.dispatch = dispatch
2 changes: 1 addition & 1 deletion bus_alt_connection/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Bus Alt Connection</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ae42d6115a36e236c9020c64527f0e9c64d8ac2cae99ed2822ba96b71544d85c
!! source digest: sha256:ab7e1b9d5721f8cb27f93c58ed77e5034bc0099105ac6d5097f1bdc74a4e6973
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/16.0/bus_alt_connection"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-bus_alt_connection"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module makes it possible to use <a class="reference external" href="https://pgbouncer.github.io/">PgBouncer</a> as a connection pooler
Expand Down

0 comments on commit f9a0b7c

Please sign in to comment.