0

I have a unit-tests for my django project.

Some of views in my django project run celery tasks and I want to check database after these tasks. I have a separated tests for the celery tasks, where I call them without .delay() method.

The main problem, what is the best and cleanest way to have a celery worker during the jenkins job?

Currently I just run nohup celery -A myqpp worker & before test and kill all running celery at the end of the job.

Nikolai Golub
  • 3,327
  • 4
  • 31
  • 61

2 Answers2

0

The best and cleanest way is not to have any celery workers during the Jenkins job, neither any queue/result backend. Utilize CELERY_ALWAYS_EAGER setting to execute your tasks in unit tests locally by blocking until the task returns.

Check out more in Celery documentation: CELERY_ALWAYS_EAGER docs

Michal Gasek
  • 6,173
  • 1
  • 18
  • 20
0

Just to extend answer about always eager mode, you can see my answer on other question, how you can run celery worker from test setUp https://stackoverflow.com/a/42107423/590233

But few tings need to be done there:

  1. Connect celery worker to test db

  2. Somehow run message broker instance ... (i think that you run it already before test, but cleanest way is to spawn broker instance from setUp as an celery worker)

Community
  • 1
  • 1
Sovetnikov
  • 439
  • 4
  • 8