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

Feature: Delete Tasks Older than a specified time - Delete All Tasks #1189

Open
0mars opened this issue Feb 15, 2022 · 3 comments
Open

Feature: Delete Tasks Older than a specified time - Delete All Tasks #1189

0mars opened this issue Feb 15, 2022 · 3 comments

Comments

@0mars
Copy link

0mars commented Feb 15, 2022

Is your feature request related to a problem? Please describe.
Due to GDPR, we have a requirement to delete tasks as they contain user info, so a specified time can be specified, for example we want to delete tasks older than 48hours

As shown the example below can be used to achieve such task

import celery
import os
import timedelta
import datetime

broker = os.environ.get('CELERY_BROKER_URL')
app = celery.Celery('tasks', broker=broker)
flower = Flower(capp=app, options=flower_options)

time_delta = timedelta(hours=48)
now = datetime.datetime.now()
delete_before_time = now-time_delta

flower.events.delete_tasks_by_time(delete_before_time.timestamp())

or

flower.events.delete_all_tasks()

Then we can a celery beat scheduler, that runs each hour, and delete the tasks

@app.task(queue='cleanup_tasks')
def clean_up_tasks():
    from flower.app import Flower

    time_delta = timedelta(hours=48)
    now = datetime.datetime.now()
    delete_before_time = now-time_delta
    flower_options = object()
    flower_options.db = 'flower'
    flower_options.persistent = True
    flower_options.purge_offline_workers = 1
    # todo: use env vars
    flower = Flower(capp=app, options=flower_options)
    flower.events.delete_tasks_by_time(delete_before_time.timestamp())

@app.on_after_configure.connect
def add_periodic(**kwargs):
    app.add_periodic_task(crontab(hour="*", minute=0), clean_up_tasks.s(), name='cleanup-tasks')

Describe the solution you'd like
The solution is based on some core function deleting tasks from the sync, while the other delete by time, checks the timestamp of each task, and delete the corrosponding task logs

@0mars
Copy link
Author

0mars commented Feb 15, 2022

#1188 please review the submitted PR as it holds the solution in the core of flower

as specified in the description:

Events:
  None delete_tasks_by_time(int to_timestamp)
  None delete_all_tasks()

@neosavvy
Copy link

neosavvy commented Sep 9, 2022

Is there a merged solution to this problem - it sure would be nice to have.

@denisolyanyuk
Copy link

I created a PR with same feature but different approach. I believe it's better because the only thing you need is to add one config object and that's all. Take a look #1310

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants