-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now we wait some time, to make sure odoo DB is up, because in some cases postgres can be just starting and marabunta would try to connect too soon, getting connection refused error! [BRANCH] bugfix-wait-db-conn-ala
- Loading branch information
Showing
2 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import time | ||
import psycopg2 | ||
|
||
from marabunta import database as database_orig | ||
|
||
|
||
class Database(database_orig.Database): | ||
"""Database subclass to allow waiting for open DB connection.""" | ||
|
||
def wait_for_connection(self, timeout): | ||
"""Wait for given connection specified amount of seconds. | ||
Args: | ||
timeout (int): number of seconds to wait till connection | ||
opens up. | ||
""" | ||
start_time = time.time() | ||
while (time.time() - start_time) < timeout: | ||
try: | ||
conn = psycopg2.connect(**self.dsn()) | ||
conn.close() | ||
return True | ||
except psycopg2.OperationalError: | ||
pass | ||
time.sleep(1) | ||
# Timed out. | ||
return False |