Skip to content

Commit

Permalink
synchrotron: Print nicer message if lock can not be acquired
Browse files Browse the repository at this point in the history
Resolves: #25
  • Loading branch information
ximion committed Aug 26, 2023
1 parent cc7df5c commit b03b48d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/laniakea/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from laniakea.utils.json import json_compact_dump
from laniakea.utils.misc import (
LockError,
cd,
listify,
stringify,
Expand Down Expand Up @@ -46,6 +47,7 @@
'safe_run',
'run_forwarded',
'safe_run_forwarded',
'LockError',
'cd',
'listify',
'stringify',
Expand Down
6 changes: 5 additions & 1 deletion src/laniakea/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def datetime_to_rfc2822_string(dt: datetime):
return utils.format_datetime(dt)


class LockError(Exception):
"""An error happened while acquiring a file lock."""


class ProcessFileLock:
"""
Simple wy to prevent multiple processes from executing the same code via a file lock.
Expand Down Expand Up @@ -169,7 +173,7 @@ def acquire(self, raise_error=True) -> bool:
self._lock_file_fd = -1
os.close(fd)
if raise_error:
raise Exception(
raise LockError(
'Unable to acquire lock "{}": Lock held by other instance or thread!'.format(self.lock_filename)
)
return False
Expand Down
2 changes: 1 addition & 1 deletion src/spears/excuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_excuses(self) -> Dict[str, SpearsExcuse]:
'Additional info:',
' days old (needed ',
)
debian_buildd_link_re = r'<a href="https://buildd\.debian\.org/status/logs\.php\?arch=[^&]+&pkg=[^&]+&ver=[^"]+" target="_blank">([^<]+)</a>'
debian_buildd_link_re = r'<a href="https://buildd\.debian\.org/status/logs\.php\?arch=[^&]+&pkg=[^&]+&ver=[^"]+" target="_blank">([^<]+)</a>' # noqa: E501

# get log data
loginfo = self._process_log_data()
Expand Down
25 changes: 17 additions & 8 deletions src/synchrotron/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from argparse import ArgumentParser

from laniakea.db import SynchrotronConfig, session_scope
from laniakea.utils import LockError
from laniakea.logging import log

from .syncengine import SyncEngine, SyncSetupError
Expand All @@ -26,12 +27,16 @@ def command_sync(options):
try:
engine = SyncEngine(options.repo_name, options.dest_suite, options.src_os, options.src_suite)
except SyncSetupError as e:
print('Unable to setup synchronization:', str(e))
print('Unable to setup synchronization:', str(e), file=sys.stderr)
sys.exit(1)

ret = engine.sync_packages(options.component, options.packages, options.force)
if not ret:
sys.exit(2)
try:
ret = engine.sync_packages(options.component, options.packages, options.force)
if not ret:
sys.exit(2)
except LockError as e:
print('Locking failed:', str(e), file=sys.stderr)
sys.exit(4)


def command_autosync(options):
Expand Down Expand Up @@ -65,12 +70,16 @@ def command_autosync(options):
autosync.source.suite_name,
)
except SyncSetupError as e:
print('Unable to setup synchronization:', str(e))
print('Unable to setup synchronization:', str(e), file=sys.stderr)
sys.exit(1)

ret = engine.autosync(autosync.auto_cruft_remove)
if not ret:
sys.exit(2)
try:
ret = engine.autosync(autosync.auto_cruft_remove)
if not ret:
sys.exit(2)
except LockError as e:
print('Locking failed:', str(e), file=sys.stderr)
sys.exit(4)

# commit pending changes
session.commit()
Expand Down

0 comments on commit b03b48d

Please sign in to comment.