-
Notifications
You must be signed in to change notification settings - Fork 32
🐛 Allow for cleanup of Redis when asyncio task is not present 🚨 #8620
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
base: master
Are you sure you want to change the base?
🐛 Allow for cleanup of Redis when asyncio task is not present 🚨 #8620
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8620 +/- ##
==========================================
+ Coverage 87.51% 89.43% +1.91%
==========================================
Files 2010 1368 -642
Lines 78979 58011 -20968
Branches 1378 154 -1224
==========================================
- Hits 69122 51884 -17238
+ Misses 9453 6077 -3376
+ Partials 404 50 -354
*This pull request uses carry forward flags. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
🧪 CI InsightsHere's what we observed from your CI run for 12abbec. ❌ Job Failures
✅ Passed Jobs With Interesting Signals
|
|
sanderegg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: will this work with multiple replicas of the service as well? I guess different replicas might have different tasks in their process
| mapping=_to_redis_hash_mapping( | ||
| { | ||
| _MARKED_FOR_REMOVAL_FIELD: True, | ||
| _MARKED_FOR_REMOVAL_AT_FIELD: datetime.datetime.now( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: why not have an optional _MARKED_FOR_REMOVAL_AT_FIELD field? if it is null it means there are no such thing. If it exists it means you want to remove it.. no need for the additional boolean.
| "the entry form Redis" | ||
| ) | ||
| ), | ||
| ] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again I do not see the point of having 2 variables here.
|
|
||
| task_to_cancel = self._created_tasks.pop(task_id, None) | ||
| if task_to_cancel is not None: | ||
| _logger.debug("Removing asyncio task related to task_id='%s'", task_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tip: use with log_context
| await self._tasks_data.delete_task_data(task_id) | ||
| else: | ||
| task_data = await self._tasks_data.get_task_data(task_id) | ||
| if task_data.marked_for_removal_at is not None and datetime.datetime.now( # type: ignore[union-attr] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see? this would simplify these if case... actually the boolean is useless here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes i tend to agree
| task_data = await self._tasks_data.get_task_data(task_id) | ||
| if task_data.marked_for_removal_at is not None and datetime.datetime.now( # type: ignore[union-attr] | ||
| tz=datetime.UTC | ||
| ) - task_data.marked_for_removal_at > datetime.timedelta( # type: ignore[union-attr] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use assert task_data.marked_for_removal_at # nosec instead of disabling pylint
| ) - task_data.marked_for_removal_at > datetime.timedelta( # type: ignore[union-attr] | ||
| seconds=_TASK_REMOVAL_MAX_WAIT | ||
| ): | ||
| _logger.debug( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with log_context here would also tell you that the function finished.
pcrespov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx. Left some comments for your consideration
BTW is wiping out the entire Redis database 6 necessary for this change?
| bool, | ||
| Field(description=("if True, indicates the task is marked for removal")), | ||
| ] = False | ||
| marked_for_removal_at: Annotated[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why is the combination
marked_for_removal_at=Falseandmarked_for_removal_at!=Noneallowed? What does it mean?
ormarked_for_removal_at=Trueandmarked_for_removal_at=None? Does this mena it can be removed anytime? but there is no gurantee of when?
| await self._tasks_data.delete_task_data(task_id) | ||
| else: | ||
| task_data = await self._tasks_data.get_task_data(task_id) | ||
| if task_data.marked_for_removal_at is not None and datetime.datetime.now( # type: ignore[union-attr] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes i tend to agree
| TEST_CHECK_STALE_INTERVAL_S: Final[float] = 1 | ||
|
|
||
|
|
||
| def strip_markd_for_removal_at(task_data: TaskData) -> TaskData: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- typo:
marked - stick to a small set of verbs e.g. CRUD or similar ones. Moreover "strip" is used in strings which has nothing to do with this.
- Here could be
clear_marked_for_removal



What do these changes do?
If a task is marked for removal and there is no entry in Redis for more than 1 minute, then it will be removed form Redis.
Why is this necessary? If an instance where and asyncio task was running is rebooted, the entry will remain in Redis. This ensures cleanup.
Related issue/s
How to test
Dev-ops 🚨
When releasing this to any deployment, do the following:
6