How to setup celery beat in django project

I am new to Django and Celery. I am trying to implement a periodic task that flushes data from Redis to ClickHouse every 5 seconds.
I am also new to a project that im working on , there is already settings like

CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'

And i found celery.py file that has some setup like

app.conf.beat_schedule = {
    'clean_messages': {
        'task': '****',
        'schedule': crontab(minute=28, hour=1),
        'args': (),
    },
    'check_statuses_from_core': {
        'task': '****',
        'schedule': crontab(minute=os.getenv('SBX_CHECK_PERIOD', '*/15')),
        'args': (),
    },

i added mine like this and they just refuse to work

'flush_ch_email': {
    'task': 'core.tasks.task_flush_clickhouse_analytics',
    'schedule': 5.0,
},
'flush_ch_attachment': {
    'task': 'core.tasks.task_flush_clickhouse_attachments',
    'schedule': 5.0,
}

If i start tasks manually everything works fine so the problem is beat ig

I havent tried using crontab , but i think it will work fine , but i need 5 seconds beat. And also im not sure with specific of databasescheduler . Maybe i have to add new service in my docker compose file to add new celery beat? or maybe something like while true loop , but im not sure if its a good idea in production

And if its a bad idea to use databasescheduler for that kind of things , what are the most optimized ways to solve my problem?

In addition before deploying on the server i created function in apps.py that setups periodic tasks and only then i saw that there is celery.py for that. Then on the server i started changing and adding mine in celery.py could that be a problem? maybe all i need is just delete that function in apps.py use the celery.py and deploy on server again?

Вернуться на верх