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

feat(tasks-processor): Add recurring task to clean up old recurring task runs #3151

Merged
merged 3 commits into from
Dec 22, 2023

Conversation

gagantrivedi
Copy link
Member

@gagantrivedi gagantrivedi commented Dec 13, 2023

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have added information to docs/ if required, so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Add a recurring task to delete recurring task runs older than RECURRING_TASK_RUN_RETENTION_DAYS

How did you test this code?

  • By running task processor manually to verify, old task runs were deleted
  • Adds unit tests

Copy link

vercel bot commented Dec 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 13, 2023 8:40am
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 13, 2023 8:40am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 13, 2023 8:40am

@github-actions github-actions bot added the api Issue related to the REST API label Dec 13, 2023
@gagantrivedi gagantrivedi changed the title Feat/recurring task cleanup feat(tasks): Add recurring task to cleanup old recurring task runs Dec 13, 2023
@gagantrivedi gagantrivedi changed the title feat(tasks): Add recurring task to cleanup old recurring task runs feat(tasks-processor): Add recurring task to clean up old recurring task runs Dec 13, 2023
Copy link
Contributor

github-actions bot commented Dec 13, 2023

Uffizzi Preview deployment-42693 was deleted.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2a9cd7c) 95.95% compared to head (6d1338d) 96.11%.
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3151      +/-   ##
==========================================
+ Coverage   95.95%   96.11%   +0.15%     
==========================================
  Files        1053     1058       +5     
  Lines       31588    31914     +326     
==========================================
+ Hits        30311    30673     +362     
+ Misses       1277     1241      -36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dabeeeenster
Copy link
Contributor

image

Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of comments but I'm happy to just approve this if you think the approach here is correct.

Comment on lines +913 to +915
RECURRING_TASK_RUN_RETENTION_DAYS = env.int(
"RECURRING_TASK_RUN_RETENTION_DAYS", default=30
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use the same retention period for both types of task?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we probably want to control this independently, e.g: we can probably go with a lower value here because it's not as critical as tasks?

Comment on lines +55 to +66
@register_recurring_task(
run_every=settings.TASK_DELETE_RUN_EVERY,
first_run_time=settings.TASK_DELETE_RUN_TIME,
)
def clean_up_old_recurring_task_runs():
if not settings.ENABLE_CLEAN_UP_OLD_TASKS:
return

now = timezone.now()
delete_before = now - timedelta(days=settings.RECURRING_TASK_RUN_RETENTION_DAYS)

RecurringTaskRun.objects.filter(finished_at__lt=delete_before).delete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that we shouldn't just use the same task as the one which removes regular tasks / task runs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's because of the name of the task mostly

@gagantrivedi gagantrivedi added this pull request to the merge queue Dec 22, 2023
Merged via the queue into main with commit 9f83f27 Dec 22, 2023
21 checks passed
@gagantrivedi gagantrivedi deleted the feat/recurring-task-cleanup branch December 22, 2023 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants