Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update Celery code owner ADR with failed attempt #345

Merged
merged 3 commits into from
Oct 12, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ Consequences
------------

* We added the new decorator as needed for all existing tasks.
* New celery tasks will need to add the same decorator. See "Rejected Alternatives" for a potential alternative.
* New celery tasks will need to add the same decorator.

(Rejected) Alternatives
-----------------------

An untested potential alternative to the ``@set_code_owner_attribute`` decorator is to try celery's `task_prerun signal`_ in an IDA, which would also ensure all future celery tasks are automatically handled. Although this is a potentially superior solution, it was missed at the time of implementation. We will not be switching to this solution at this time given we have a working solution and other priorities, but it is a potentially viable solution if the need arises.
Celery has a `task_prerun signal`_ that would allow us to execute code every time a task is about to start.

Additionally, if this alternative solution were implemented, it would be best to not add celery as a dependency to this library, and to document a new edx-platform implementation. It is unlikely that the solution will be needed outside of edx-platform.
This possibility was discovered after we had already annotated tasks. We hoped this would ensure all celery tasks were automatically handled rather than requiring explicit decorators. However, when we `trialed the task_prerun approach <https://github.com/openedx/edx-platform/pull/33180>`_ we discovered that no attribute was set on the Celery tasks. This seems to be because New Relic instruments the task function itself with transaction-start and transaction-end calls, so any signals that are run before or after the task execution occur outside the scope of the transaction.

Theoretically, we could do something similar to New Relic's monkeypatching in order to inject a code owner attribute call, but this would be fragile and could lead to disruptive failures.

.. _task_prerun signal: https://docs.celeryproject.org/en/stable/userguide/signals.html#task-prerun

Changelog
---------

* 2023-09-19: Updated ``task_prerun`` alternative with results of a failed attempt at using it.
Loading