Skip to content

Commit

Permalink
Notifications: initialize exception properly (#11019)
Browse files Browse the repository at this point in the history
* Notifications: initialize exception properly

Required `message_id` was missing when initializing the exception.

* Notifications: define the message

* Update readthedocs/projects/notifications.py

Co-authored-by: Santos Gallegos <[email protected]>

---------

Co-authored-by: Santos Gallegos <[email protected]>
  • Loading branch information
humitos and stsewd authored Jan 10, 2024
1 parent 135be78 commit ce0b582
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions readthedocs/projects/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ class RepositoryError(BuildUserError):
class SyncRepositoryLocked(BuildAppError):

"""Error risen when there is another sync_repository_task already running."""

REPOSITORY_LOCKED = "project:repository:locked"
16 changes: 15 additions & 1 deletion readthedocs/projects/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from django.utils.translation import gettext_noop as _

from readthedocs.notifications.constants import ERROR, INFO
from readthedocs.notifications.constants import ERROR, INFO, WARNING
from readthedocs.notifications.messages import Message, registry
from readthedocs.projects.exceptions import (
ProjectConfigurationError,
RepositoryError,
SyncRepositoryLocked,
UserFileNotFound,
)

Expand Down Expand Up @@ -131,5 +132,18 @@
),
type=ERROR,
),
Message(
id=SyncRepositoryLocked.REPOSITORY_LOCKED,
header=_("Repository locked"),
body=_(
textwrap.dedent(
"""
We can't perform the versions/branches synchronize at the moment.
There is another sync already running.
"""
).strip(),
),
type=WARNING,
),
]
registry.add(messages)
2 changes: 1 addition & 1 deletion readthedocs/projects/tasks/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def sync_repository_task(self, version_id, *, build_api_key, **kwargs):
# by a different worker.
# See https://github.com/readthedocs/readthedocs.org/pull/9021/files#r828509016
if not lock_acquired:
raise SyncRepositoryLocked
raise SyncRepositoryLocked(SyncRepositoryLocked.REPOSITORY_LOCKED)

self.execute()

Expand Down

0 comments on commit ce0b582

Please sign in to comment.