Koed00 / django-q

A multiprocessing distributed task queue for Django
https://django-q.readthedocs.org
MIT License
1.83k stars 289 forks source link

django-q scheduler creating multiple entries in the db for the same task #566

Open RajuSingh-cmyk opened 3 years ago

RajuSingh-cmyk commented 3 years ago

i want to run djangoq-scheduler on every weekend but having two issues with it-:

i) creating two entries in django_q_scheduler models as soon as i run development server and qcluster

ii) scheduler starts executing immediately as soon as entry is created in the model, instead of executing on every weekend.

Here is the code used -:

Django-Q Cluster

Q_CLUSTER = {

'name': 'DjangQORM',

'max_attempts': 1,

'retry': 14400,

'orm': 'default'

}

Schedule.objects.create(func='func()',

                    schedule_type=Schedule.CRON,

                    cron='30 18 * * 6',
                    repeats = -1

                    )

Version Used -

python-> 3.6.8

django-q -> 1.3.4

Database- postgres

OS - Linux

Any help would be greatly appreciated.

jyoost commented 3 years ago

Try setting Schedule.next_run to the first time you want it to run.

Your code indicates it gets set to timezone.now (the default, since you are not setting it explicitly )

RajuSingh-cmyk commented 3 years ago

@jyoost Thanks for the help!! The second issue of immediate task execution is resolved by using next_run.

Could you please suggest a work around for first issue, i.e creating new entries everytime the development server is redeployed?

Koed00 commented 3 years ago

Schedules are just a django model so you can treat them like any other startup data: