Skip to content

Commit

Permalink
feat(post links and version: add some identifying data to celery slac…
Browse files Browse the repository at this point in the history
…k message/
  • Loading branch information
YishaiGlasner committed Sep 9, 2024
1 parent 2c7baba commit f999791
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,8 @@ def internal_do_post():
skip_links = bool(int(request.POST.get("skip_links", 0)))
count_after = int(request.POST.get("count_after", 0))
version_change = VersionChange(raw_version=data, uid=request.user.id, method=method, patch=patch, count_after=count_after, skip_links=skip_links)
return save_changes([asdict(version_change)], save_version, method)
task_title = f'Version Post: {data["title"]} / {data["versionTitle"]} / {data["language"]}'
return save_changes([asdict(version_change)], save_version, method, task_title)

if request.method == "POST":
patch = False
Expand Down Expand Up @@ -1985,7 +1986,8 @@ def _internal_do_post(request, obj, uid, method, skip_check, override_preciselin
link["_override_preciselink"] = True
links.append(asdict(LinkChange(raw_link=link, uid=uid, method=method)))

return save_changes(links, save_link, method)
task_title = f'Links Post. First link: {obj[0]["refs"][0]}-{obj[0]["refs"][1]}'
return save_changes(links, save_link, method, task_title)

def _internal_do_delete(request, link_id_or_ref, uid):
obj = tracker.delete(uid, Link, link_id_or_ref, callback=revarnish_link)
Expand Down
8 changes: 4 additions & 4 deletions sefaria/helper/texts/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
def should_run_with_celery(from_api):
return CELERY_ENABLED and from_api

def save_changes(changes, func, method):
def save_changes(changes, func, method, task_title=''):
if should_run_with_celery(method == 'API'):
main_task_id = str(uuid.uuid4())
tasks = [save_change.s(func.__name__, c).set(queue=CELERY_QUEUES['tasks']) for c in changes]
job = chord(tasks, inform.s(main_task_id=main_task_id).set(queue=CELERY_QUEUES['tasks']))(task_id=main_task_id)
job = chord(tasks, inform.s(main_task_id=main_task_id, task_title=task_title).set(queue=CELERY_QUEUES['tasks']))(task_id=main_task_id)
tasks_ids = [task.id for task in job.parent.results]
return celeryResponse(job.id, tasks_ids)
else:
Expand Down Expand Up @@ -59,8 +59,8 @@ def save_change(func_name, raw_history_change):
return repr(e)

@app.task(name="web.inform", acks_late=True)
def inform(results, main_task_id):
title = f'Results for celery main task with id {main_task_id}'
def inform(results, main_task_id, task_title):
title = f'{task_title} (celery main task id {main_task_id})'
results = '\n'.join([f'{k}: {v}.' for k, v in Counter(results).items()])
send_message('#engineering-signal', 'Text Upload', title, results, icon_emoji=':leafy_green:')

Expand Down

0 comments on commit f999791

Please sign in to comment.