Refactor fetching tasks to process
@emyller is already working on this.
Since May 19, 2025.
Assessment
This issue has not been assessed yet.
Description
A couple issues have been observed around the database function responsible for retrieving and locking tasks to process.
1. Result inconsistency.
Especially when running tests, somewhat often the database query will return no results, leading to flaky test failures, e.g.
def test_run_task_runs_task_and_creates_task_run_object_when_success(
database: str,
dummy_task: TaskHandler[[str, str]],
) -> None:
# Given
task = Task.create(dummy_task.task_identifier, scheduled_for=timezone.now())
task.save(using=database)
# When
task_runs = run_tasks(database)
# Then
> assert cache.get(DEFAULT_CACHE_KEY)
E AssertionError: assert None
E + where None = get('foo')
E + where get = <django.utils.connection.ConnectionProxy object at 0x107958080>.get
tests/unit/task_processor/test_unit_task_processor_processor.py:93: AssertionError
We became suspicious of a time zone issue so we forced UTC in both test databases as an experiment to confirm the bug. While the change led to tests passing consistently, eventually the same exception has randomly arose again.
We're still not sure what causes this. Time might be involved.
2. Locked tasks
Since the database function will select N tuples and lock them in-query, and if the associated Django queryset is not exhausted — e.g. because of an exception, we'll result in a state with tasks locked but never processed.
Related code:
The current implementation wraps running tasks within a try/except block which should prevent dangling tasks. Still, the design could be improved, and perhaps future-proofed, by using the Django ORM to somehow achieve a similar effect and efficiency.
- Dominant language
- Python
- Stars
- 2
- Forks
- 4
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 10
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Flagsmith/flagsmith-common
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Flagsmith/flagsmith-common#250 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Flagsmith/flagsmith-common#198 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Flagsmith/flagsmith-common#254 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Flagsmith/flagsmith-common#252 ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
Flagsmith/flagsmith-common#245 ·
All issues in Flagsmith/flagsmith-common
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·