Skip to content

Commit

Permalink
Merge pull request #4597 from zenoss/bugfix/ZEN-35127.6x
Browse files Browse the repository at this point in the history
Raise SystemExit when unable to get a ZODB connection.
  • Loading branch information
jpeacock-zenoss authored Nov 5, 2024
2 parents ee1eeb3 + e82583a commit 682fffa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
13 changes: 6 additions & 7 deletions Products/Jobber/tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
from mock import call, Mock, patch

from Products.Jobber.worker import (
setup_zodb,
MySQLdb,
setup_zodb,
_OPERATIONAL_ERROR_RETRY_DELAY,
_WORKER_TIMEOUT_OFFSET,
)

PATH = {"src": "Products.Jobber.worker"}
Expand Down Expand Up @@ -76,14 +75,14 @@ def test_operational_error(t, time_, getConfig_, get_app_, zodb_):
call(_OPERATIONAL_ERROR_RETRY_DELAY),
call(_OPERATIONAL_ERROR_RETRY_DELAY),
call(_OPERATIONAL_ERROR_RETRY_DELAY),
call(timeout + _WORKER_TIMEOUT_OFFSET),
)

setup_zodb()
with t.assertRaises(SystemExit):
setup_zodb()

time_.sleep.assert_has_calls(sleep_calls)
t.assertEqual(
len(sleep_calls) - 1, zodb_.config.databaseFromURL.call_count
len(sleep_calls), zodb_.config.databaseFromURL.call_count
)
t.assertEqual(len(sleep_calls), time_.sleep.call_count)

Expand All @@ -105,7 +104,7 @@ def test_unexpected_error(t, time_, getConfig_, get_app_, zodb_):
config = {"zodb-config-file": filename}
getConfig_.return_value = config

setup_zodb()
with t.assertRaises(SystemExit):
setup_zodb()

t.assertEqual(1, zodb_.config.databaseFromURL.call_count)
time_.sleep.assert_called_once_with(timeout + _WORKER_TIMEOUT_OFFSET)
12 changes: 2 additions & 10 deletions Products/Jobber/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
from .config import getConfig
from .utils.app import get_app

_DEFAULT_WORKER_PROC_ALIVE_TIMEOUT = 4.0 # Celery default
_OPERATIONAL_ERROR_RETRY_DELAY = 0.1
_WORKER_TIMEOUT_OFFSET = 10
_OPERATIONAL_ERROR_RETRY_DELAY = 0.5
_mlog = logging.getLogger("zen.zenjobs.worker")


Expand Down Expand Up @@ -124,13 +122,7 @@ def setup_zodb(**kw):
break
else:
log.error("failed to initialize ZODB connection: %s", error)
timeout = app.conf.get(
"worker_proc_alive_timeout", _DEFAULT_WORKER_PROC_ALIVE_TIMEOUT
)
# Add time to the worker_proc_alive_timeout config to force Celery
# to kill this worker. If the database connection cannot be
# initialized, this worker instance is useless.
time.sleep(timeout + _WORKER_TIMEOUT_OFFSET)
raise SystemExit("Unable to initialize ZODB connection")


def teardown_zodb(**kw):
Expand Down

0 comments on commit 682fffa

Please sign in to comment.