Skip to content

Commit d77e47f

Browse files
authored
chore: Add more logging to cleanup command (#68915)
The process is still dying in a hard to understand position.
1 parent 2dd164f commit d77e47f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/sentry/runner/commands/cleanup.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def get_project(value: str) -> int | None:
4242
API_TOKEN_TTL_IN_DAYS = 30
4343

4444

45+
def debug_output(msg: str) -> None:
46+
if os.environ.get("SENTRY_CLEANUP_SILENT", None):
47+
return
48+
click.echo(msg)
49+
50+
4551
def multiprocess_worker(task_queue: _WorkQueue) -> None:
4652
# Configure within each Process
4753
import logging
@@ -70,12 +76,15 @@ def multiprocess_worker(task_queue: _WorkQueue) -> None:
7076
while True:
7177
j = task_queue.get()
7278
if j == _STOP_WORKER:
79+
debug_output("Received STOP_WORKER task")
7380
task_queue.task_done()
81+
7482
return
7583

76-
model, chunk = j
77-
model = import_string(model)
84+
model_name, chunk = j
85+
debug_output(f"Starting deletion work for {model_name}:{chunk}")
7886

87+
model = import_string(model_name)
7988
try:
8089
task = deletions.get(
8190
model=model,
@@ -85,11 +94,13 @@ def multiprocess_worker(task_queue: _WorkQueue) -> None:
8594
)
8695

8796
while True:
97+
debug_output(f"Running chunk for {model_name}")
8898
if not task.chunk():
8999
break
90100
except Exception as e:
91101
logger.exception(e)
92102
finally:
103+
debug_output(f"Completed deletion work for {model_name}:{chunk}")
93104
task_queue.task_done()
94105

95106

@@ -138,11 +149,8 @@ def cleanup(
138149
raise click.Abort()
139150

140151
os.environ["_SENTRY_CLEANUP"] = "1"
141-
142-
def debug_output(msg: str) -> None:
143-
if silent:
144-
return
145-
click.echo(msg)
152+
if silent:
153+
os.environ["SENTRY_CLEANUP_SILENT"] = "1"
146154

147155
# Make sure we fork off multiprocessing pool
148156
# before we import or configure the app
@@ -368,6 +376,7 @@ def is_filtered(model: type[Model]) -> bool:
368376
for chunk in q.iterator(chunk_size=100):
369377
task_queue.put((imp, chunk))
370378

379+
debug_output("Waiting for task_queue to drain")
371380
task_queue.join()
372381

373382
# Clean up FileBlob instances which are no longer used and aren't super

0 commit comments

Comments
 (0)