How to create one executable file with celery tasks

I have successfully learned some of the basics of Celery, but I have not found an easy way to create one executable file (without having to run celerybeat as a separate process to perform periodic tasks). You can write an application and start its workflow ( http://docs.celeryproject.org/en/3.1/userguide/application.html ):

from datetime import timedelta
from celery import Celery
app = Celery()

@app.task
def test():
    print("he-he")

app.conf.update(
    BROKER_URL="redis://localhost:6379",
    CELERY_RESULT_BACKEND="redis://localhost:6379",
    CELERY_ACCEPT_CONTENT=["application/json"],
    CELERY_TASK_SERIALIZER="json",
    CELERY_RESULT_SERIALIZER="json",
    CELERYBEAT_SCHEDULE={
        'runs-every-30-seconds': {
            'task': '__main__.test',
            'schedule': timedelta(seconds=30),
        },
    }
)

if __name__ == '__main__':
   app.worker_main()

But how can I start the beating process from the same module to run periodic tasks (so as not to start the celerybeat daemon as a separate executable file)? This is important because I would like to use pyinstaller, so a dedicated Python interpreter will not be available on client machines.

! !

+4
1

, , , . .

:

# that the class to run the beat process
from celery.bin.beat import beat
# your app
from celery_tasks import app

if __name__ == "__main__":
    beat(app=app).run()

!

0

Source: https://habr.com/ru/post/1664799/


All Articles