Periodic tasks not working
See original GitHub issueI can’t seem to get the periodic tasks to execute, or show up in the ‘scheduled’ queue.
Using the following tasks.py for debug:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import redis
from tasktiger import TaskTiger
from tasktiger.schedule import periodic
tiger = TaskTiger()
@tiger.task(schedule=periodic(seconds=1), queue='periodic')
def periodic_task():
"""Periodic task."""
conn = redis.Redis(decode_responses=True)
conn.incr('period_count', 1)
@tiger.task()
def test_task():
"""Minimal task."""
print('Hello')
Running tasktiger as shown in docs:
$ PYTHONPATH=. tasktiger
I can run the minimal test_task:
>>> import tasks
>>> tasks.test_task.delay()
<Task <function test_task at 0x7f03aaacfd08>>
I see the output in the log, but there is no evidence of the periodic_task and the redis key ‘period_count’ never increments:
{"pid": 27295, "queues": [], "exclude_queues": [], "single_worker_queues": [], "event": "ready", "level": "info", "timestamp": "2017-10-26T12:43:35.236665Z"}
{"pid": 27295, "queue": "default", "event": "new queue", "level": "debug", "timestamp": "2017-10-26T12:44:09.818470Z"}
{"pid": 27295, "queue": "default", "src_queue": "queued", "dest_queue": "active", "qty": 1, "event": "moved tasks", "level": "debug", "timestamp": "2017-10-26T12:44:09.819402Z"}
{"pid": 27295, "queue": "default", "child_pid": 27318, "func": "tasks:test_task", "task_id": "c44b198caac44250d06fc5dfc3249960d9eb5bfbe76d8bb848ddb419c8382323", "params": {"args": [], "kwargs": {}}, "event": "processing", "level": "info", "timestamp": "2017-10-26T12:44:09.820179Z"}
Hello
{"pid": 27295, "queue": "default", "attempted": 1, "processed": 1, "event": "processed", "level": "debug", "timestamp": "2017-10-26T12:44:09.823499Z"}
{"pid": 27295, "queue": "default", "task_id": "c44b198caac44250d06fc5dfc3249960d9eb5bfbe76d8bb848ddb419c8382323", "event": "done", "level": "info", "timestamp": "2017-10-26T12:44:09.825171Z"}
{"pid": 27295, "queue": "default", "src_queue": "queued", "dest_queue": "active", "qty": 0, "event": "moved tasks", "level": "debug", "timestamp": "2017-10-26T12:44:09.825592Z"}
{"pid": 27295, "time_total": 60.00032615661621, "time_busy": 0.003787517547607422, "utilization": 0.006312494931645924, "event": "stats", "level": "info", "timestamp": "2017-10-26T12:44:35.237246Z"}
Am I missing something?
By the way, TaskTiger is a great project!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
celery periodic tasks not executing - Stack Overflow
The short answer is to just add -B to your celery worker command, e.g. celery -A proj worker -B . This isn't recommended...
Read more >Celery periodic tasks are not running · Issue #330 - GitHub
I am running the celery-beat, celery and django all in a docker compose environment. The celery worker is picking up the tasks from...
Read more >Periodic Tasks — Celery 5.2.7 documentation
Introduction¶. celery beat is a scheduler; It kicks off tasks at regular intervals, that are then executed by available worker nodes in the...
Read more >Asynchronous Tasks With Django and Celery - Real Python
In this tutorial, you'll learn how to integrate Celery and Django using Redis as a message broker. You'll refactor the synchronous email ...
Read more >[4.0.2] Celery Beat scheduling not working due to an assert ...
We have no problems with executing tasks in the system, or manually starting them. ... we don't see any scheduled tasks and no...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually @jkemp101 , I think I see what the problem is based on the comments in the test:
https://github.com/closeio/tasktiger/blob/6973a28e7a0c2912a5fb651376a0fd819b9ed713/tests/test_periodic.py#L61
My issue was that I was creating a fresh
TaskTiger
instance when running the worker instead of using the same one where the periodic task was defined. When I import the same instance that I used when defining the tasks, things work as expected. If somebody else on this issue can confirm that this fixes the issue for them, I will issue a PR for docs updates.@mrname I was also creating a fresh TaskTiger instance. I confirm this fixes the issue with periodic tasks not being scheduled