Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions apps/worker/tasks/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def run_impl(
):
milestone = Milestones.NOTIFICATIONS_SENT
redis_connection = get_redis_connection()

bc_kwargs = {
"commit_sha": commitid,
"repo_id": repoid,
"task_name": self.name,
"parent_task_id": self.request.parent_id,
}

if self.has_upcoming_notifies_according_to_redis(
redis_connection, repoid, commitid
):
Expand All @@ -89,10 +97,7 @@ def run_impl(
)
self.log_checkpoint(UploadFlow.SKIPPING_NOTIFICATION)
self._call_upload_breadcrumb_task(
commit_sha=commitid,
repo_id=repoid,
milestone=milestone,
error=Errors.INTERNAL_OTHER_JOB,
milestone=milestone, error=Errors.INTERNAL_OTHER_JOB, **bc_kwargs
)
return {
"notified": False,
Expand All @@ -107,21 +112,32 @@ def run_impl(
lock_timeout=max(80, self.hard_time_limit_task),
)

self._call_upload_breadcrumb_task(
milestone=Milestones.LOCK_ACQUIRING, **bc_kwargs
)

try:
lock_acquired = False
with lock_manager.locked(
lock_type=LockType.NOTIFICATION,
retry_num=self.attempts,
):
lock_acquired = True
return self.run_impl_within_lock(
self._call_upload_breadcrumb_task(
milestone=Milestones.LOCK_ACQUIRED, **bc_kwargs
)
result = self.run_impl_within_lock(
db_session,
repoid=repoid,
commitid=commitid,
current_yaml=current_yaml,
empty_upload=empty_upload,
**kwargs,
)
self._call_upload_breadcrumb_task(
milestone=Milestones.LOCK_RELEASED, **bc_kwargs
)
return result
except LockRetry as err:
(
log.info(
Expand All @@ -136,16 +152,10 @@ def run_impl(
)
self.log_checkpoint(UploadFlow.NOTIF_LOCK_ERROR)
self._call_upload_breadcrumb_task(
commit_sha=commitid,
repo_id=repoid,
milestone=milestone,
error=Errors.INTERNAL_LOCK_ERROR,
milestone=milestone, error=Errors.INTERNAL_LOCK_ERROR, **bc_kwargs
)
self._call_upload_breadcrumb_task(
commit_sha=commitid,
repo_id=repoid,
milestone=milestone,
error=Errors.INTERNAL_OTHER_JOB,
milestone=milestone, error=Errors.INTERNAL_OTHER_JOB, **bc_kwargs
)
return {
"notified": False,
Expand Down Expand Up @@ -175,12 +185,17 @@ def _attempt_retry(
*args,
**kwargs,
):
bc_kwargs = {
"commit_sha": commit.commitid,
"repo_id": commit.repoid,
"task_name": self.name,
"parent_task_id": self.request.parent_id,
}
try:
self._call_upload_breadcrumb_task(
commit_sha=commit.commitid,
repo_id=commit.repoid,
milestone=Milestones.NOTIFICATIONS_SENT,
error=Errors.INTERNAL_RETRYING,
**bc_kwargs,
)
self.retry(max_retries=max_retries, countdown=countdown)
except MaxRetriesExceededError:
Expand All @@ -196,10 +211,9 @@ def _attempt_retry(
)
self.log_checkpoint(UploadFlow.NOTIF_TOO_MANY_RETRIES)
self._call_upload_breadcrumb_task(
commit_sha=commit.commitid,
repo_id=commit.repoid,
milestone=Milestones.NOTIFICATIONS_SENT,
error=Errors.INTERNAL_OUT_OF_RETRIES,
**bc_kwargs,
)
return {
"notified": False,
Expand All @@ -218,6 +232,10 @@ def run_impl_within_lock(
**kwargs,
):
milestone = Milestones.NOTIFICATIONS_SENT
bc_kwargs = {
"task_name": self.name,
"parent_task_id": self.request.parent_id,
}

log.info("Starting notifications", extra={"commit": commitid, "repoid": repoid})
commits_query = db_session.query(Commit).filter(
Expand All @@ -237,6 +255,7 @@ def run_impl_within_lock(
repo_id=commit.repoid,
milestone=Milestones.NOTIFICATIONS_SENT,
error=Errors.SKIPPED_NOTIFICATIONS,
**bc_kwargs,
)
return {
"notify_attempted": False,
Expand Down Expand Up @@ -266,6 +285,7 @@ def run_impl_within_lock(
repo_id=repoid,
milestone=milestone,
error=Errors.REPO_MISSING_VALID_BOT,
**bc_kwargs,
)
return {"notified": False, "notifications": None, "reason": "no_valid_bot"}
except NoConfiguredAppsAvailable as exp:
Expand All @@ -290,6 +310,7 @@ def run_impl_within_lock(
repo_id=repoid,
milestone=milestone,
error=Errors.INTERNAL_APP_RATE_LIMITED,
**bc_kwargs,
)
return self._attempt_retry(
max_retries=10,
Expand Down Expand Up @@ -339,6 +360,7 @@ def run_impl_within_lock(
repo_id=commit.repoid,
milestone=milestone,
error=Errors.GIT_CLIENT_ERROR,
**bc_kwargs,
)
return {
"notified": False,
Expand All @@ -356,6 +378,7 @@ def run_impl_within_lock(
repo_id=commit.repoid,
milestone=milestone,
error=Errors.GIT_CLIENT_ERROR,
**bc_kwargs,
)
return {
"notified": False,
Expand Down Expand Up @@ -439,6 +462,7 @@ def run_impl_within_lock(
repo_id=commit.repoid,
milestone=milestone,
error=Errors.SKIPPED_NOTIFICATIONS,
**bc_kwargs,
)
return {
"notified": False,
Expand All @@ -459,6 +483,7 @@ def run_impl_within_lock(
repo_id=commit.repoid,
milestone=milestone,
error=Errors.REPORT_NOT_FOUND,
**bc_kwargs,
)
return {
"notified": False,
Expand Down Expand Up @@ -504,6 +529,7 @@ def run_impl_within_lock(
commit_sha=commit.commitid,
repo_id=commit.repoid,
milestone=milestone,
**bc_kwargs,
)
log.info(
"Notifications done",
Expand All @@ -528,6 +554,7 @@ def run_impl_within_lock(
repo_id=commit.repoid,
milestone=milestone,
error=Errors.SKIPPED_NOTIFICATIONS,
**bc_kwargs,
)
return {"notified": False, "notifications": None}

Expand Down Expand Up @@ -742,6 +769,8 @@ def submit_third_party_notifications(
milestone=Milestones.NOTIFICATIONS_SENT,
error=Errors.UNKNOWN,
error_text=repr(e),
task_name=self.name,
parent_task_id=self.request.parent_id,
)
raise

Expand Down
Loading
Loading