Skip to content

Commit 5ff3d10

Browse files
authored
Celery: user builder instead of instance as argument (#11337)
It seems that `CeleryTaskWrapper` from New Relic passes their own `instance=` attribute and the Celery task attributes as well as `kwargs`. This results in passing `instance` attribute twice and it breaks: https://read-the-docs.sentry.io/issues/5385629903/?project=148442&query=is%3Aunresolved+%21message%3A%22%21message%3A%22%21message%3A%22SystemExit%22+%21message%3A%22frame-ancestors%22&referrer=issue-stream&statsPeriod=14d&stream_index=0 This commit renames `instance` argument to `builder` to avoid this.
1 parent 757984f commit 5ff3d10

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

readthedocs/projects/tasks/builds.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def before_start(self, task_id, args, kwargs):
430430
# once we don't need to rely on `self.data.project`.
431431
if self.data.project.has_feature(Feature.SCALE_IN_PROTECTION):
432432
set_builder_scale_in_protection.delay(
433-
instance=socket.gethostname(),
433+
builder=socket.gethostname(),
434434
protected_from_scale_in=True,
435435
)
436436

@@ -746,7 +746,7 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
746746
# Disable scale-in protection on this instance
747747
if self.data.project.has_feature(Feature.SCALE_IN_PROTECTION):
748748
set_builder_scale_in_protection.delay(
749-
instance=socket.gethostname(),
749+
builder=socket.gethostname(),
750750
protected_from_scale_in=False,
751751
)
752752

readthedocs/projects/tasks/utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ def send_external_build_status(version_type, build_pk, commit, status):
165165

166166

167167
@app.task(queue="web")
168-
def set_builder_scale_in_protection(instance, protected_from_scale_in):
168+
def set_builder_scale_in_protection(builder, protected_from_scale_in):
169169
"""
170-
Set scale-in protection on this builder ``instance``.
170+
Set scale-in protection on this builder ``builder``.
171171
172-
This way, AWS will not scale-in this instance while it's building the documentation.
172+
This way, AWS will not scale-in this builder while it's building the documentation.
173173
This is pretty useful for long running tasks.
174174
"""
175-
log.bind(instance=instance, protected_from_scale_in=protected_from_scale_in)
175+
log.bind(builder=builder, protected_from_scale_in=protected_from_scale_in)
176176

177177
if settings.DEBUG or settings.RTD_DOCKER_COMPOSE:
178178
log.info(
@@ -188,7 +188,7 @@ def set_builder_scale_in_protection(instance, protected_from_scale_in):
188188
)
189189

190190
# web-extra-i-0c3e866c4e323928f
191-
hostname_match = re.match(r"([a-z\-]+)-(i-[a-f0-9]+)", instance)
191+
hostname_match = re.match(r"([a-z\-]+)-(i-[a-f0-9]+)", builder)
192192
if not hostname_match:
193193
log.warning(
194194
"Unable to set scale-in protection. Hostname name matching not found.",

0 commit comments

Comments
 (0)