Koed00 / django-q

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

Can't pass a datetime as task arg in Scheduled #328

Open yannbu opened 5 years ago

yannbu commented 5 years ago

I'm having a 01:04:50 [Q] ERROR malformed node or string: <_ast.Call object at 0x1075c50f0> error in my qcluster when passing a datetime as task argument of a Schedule.

Do Schedules accept complex types as args? I have tested int and str myself, it works OK, but datetime breaks everything. Also, I don't see examples with types other than int and str in the documentation.

Here is my code and setup:

import datetime

from django.core.management.base import BaseCommand

from django_q.tasks import schedule
from django_q.models import Schedule

from dateutil.tz import tzlocal

def extract_date(datetime_):
    return datetime_.date()

class Command(BaseCommand):
    help = "Test Command"

    def handle(self, *args, **options):

        now = datetime.datetime.now(tzlocal())

        schedule('extract_date',
                 datetime.datetime.now(),
                 schedule_type=Schedule.MINUTES,
                 minutes=1,
                 repeats=-1,
                 next_run=now.replace(second=now.second + 10))

OS: Mac OS 10.14 Python: 3.6.0 Django==2.4.2 django-q==1.0.1

Thanks!

yannbu commented 5 years ago

Do Schedules accept complex types as args?

I think the answer is no, right ? Because of this:

https://github.com/Koed00/django-q/blob/35ba23de897e89d2065d1c86182d2d2b6c39791a/django_q/cluster.py#L501

kbuilds commented 5 years ago

You can pass a datetime as a string, which can then be converted back into a native Python datetime within the task itself