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

Periodic tasks not working #91

Open
lukemaxwell opened this issue Oct 26, 2017 · 6 comments
Open

Periodic tasks not working #91

lukemaxwell opened this issue Oct 26, 2017 · 6 comments

Comments

@lukemaxwell
Copy link

lukemaxwell commented Oct 26, 2017

I 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!

@xuru
Copy link

xuru commented Dec 18, 2017

I ran across this issue as well even when passing -m mymodule to tasktiger. I finally figured out a solution that works. I use click for cli commands, and made one to fire off a worker:

@tasks.command("worker")
def start_worker():
    secho(f"Starting worker", fg="green")
    from mymodule.tasks import process_events, process_other_events, process_events_for_specific_email  # register the tasks

    tiger.run_worker(module='mymodule')
    sys.exit(0)

Hope this helps!

@EverCurse
Copy link

yeah , i meet same question

@mrname
Copy link

mrname commented Aug 28, 2018

I seem to have the same problem as well. Any updates on this? I'm happy to look into it if nobody else is.

@jkemp101
Copy link
Member

Does the example in the op work for you if you run tasktiger like this so it processes the periodic queue?
PYTHONPATH=. tasktiger -q periodic

@mrname
Copy link

mrname commented Aug 28, 2018

Actually @jkemp101 , I think I see what the problem is based on the comments in the test:

# After the first worker run, the periodic task will be queued.

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.

@thomasleveil
Copy link

@mrname I was also creating a fresh TaskTiger instance. I confirm this fixes the issue with periodic tasks not being scheduled

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

No branches or pull requests

6 participants