coleifer / huey

a little task queue for python
https://huey.readthedocs.io/
MIT License
5.12k stars 366 forks source link

Dynamic Schedule Tasks in Django with Crontab in minutes #495

Closed arbazkiraak closed 4 years ago

arbazkiraak commented 4 years ago
from huey import crontab
from huey.contrib.djhuey import periodic_task, task

@task()
def schedule_message(project_id,cron_minutes,cron_hours='*'):
    def wrapper():
        SubdomainScanner(project_id)

    schedule = crontab(cron_minutes,cron_hours)
    task_name = 'subdomain_scanner_task_{}'.format(project_id)

    periodic_task(schedule,name=task_name)(wrapper)
from .tasks import *
schedule_message('google.com','*/1')
python3 manage.py run_huey -w 2
[2020-02-27 06:00:11,428] INFO:huey.consumer:MainThread:Huey consumer started with 2 thread, PID 1412 at 2020-02-27 06:00:11.428149
[2020-02-27 06:00:11,428] INFO:huey.consumer:MainThread:Scheduler runs every 1 second(s).
[2020-02-27 06:00:11,428] INFO:huey.consumer:MainThread:Periodic tasks are enabled.
[2020-02-27 06:00:11,429] INFO:huey.consumer:MainThread:The following commands are available:
+ mainapp.tasks.schedule_message
coleifer commented 4 years ago

https://huey.readthedocs.io/en/latest/guide.html#dynamic-periodic-tasks

arbazkiraak commented 4 years ago

Hello @coleifer ,

It works, I wanted to ask how to dynamically remove or update the schedule_message by their task_name ?