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

Celery/Redbeat cron tasks with diffrent timezones wont run at time #222

Open
thisiseddy-ab opened this issue Jul 23, 2022 · 5 comments
Open

Comments

@thisiseddy-ab
Copy link

Celery cron tasks wont run at time, how to properly configure it?
I don't know is something wrong with celery, or redbeat or redis.

Celery==5.2.7 (dawn-chorus)
celery-redbeat==2.0.0
redis==4.3.4

First Method

Celery Configuration

broker_url = "redis://localhost:6379/0"
result_backend = "redis://localhost:6379/1"

timezone = "Europe/Vienna"
enable_utc = False

redbeat_redis_url = "redis://localhost:6379/2"

beat_scheduler = 'redbeat.RedBeatScheduler'
beat_max_loop_interval = 5

beat_schedule = {}

Creating the Task

    dif_tz = timezone("Europe/London")
    nowfun = lambda: datetime.now(dif_tz)
    p_task = Entry(
        name= "crontab_task_tz_1",
        task = "task.print_word",
        schedule = crontab(minute="5",hour="21",day_of_month="*",month_of_year="*", day_of_week="*",nowfun=nowfun),
        args=["Crontab Diffrent Timezone"],
        app = celery
    )
    p_task.save()

Second Method

Celery Configuration

broker_url = "redis://localhost:6379/0"
result_backend = "redis://localhost:6379/1"

timezone = "UTC"
enable_utc = True

redbeat_redis_url = "redis://localhost:6379/2"

beat_scheduler = 'redbeat.RedBeatScheduler'
beat_max_loop_interval = 5

beat_schedule = {}

Creating the Task

    dif_tz = timezone("Europe/London")
    local_dt = dif_tz.localize(datetime.now())
    dt_to_celery = local_dt.astimezone(UTC)
    nowfun = lambda: dt_to_celery
    p_task = Entry(
        name= "crontab_task_tz_1",
        task = "task.print_word",
        schedule = crontab(minute="5",hour="21",day_of_month="*",month_of_year="*", day_of_week="*",nowfun=nowfun),
        args=["Crontab Diffrent Timezone"],
        app = celery
    )
    p_task.save()
@rahularadhe1
Copy link

Hi, we are in the exact same situation as this, did you find any solution to this issue?

@thisiseddy-ab
Copy link
Author

Hi, we are in the exact same situation as this, did you find any solution to this issue?

No, no one answers and i tried every stackowerflow solution and it does not work.

@kalekseev
Copy link

nowfun argument of crontab is not supported in redbeat serialiser https://github.com/sibson/redbeat/blob/main/redbeat/decoder.py#L94-L102

@thisiseddy-ab
Copy link
Author

nowfun argument of crontab is not supported in redbeat serialiser https://github.com/sibson/redbeat/blob/main/redbeat/decoder.py#L94-L102

what do you suggest what to use to run crontask with different timezone

@kalekseev
Copy link

@thisiseddy-ab add nowfun support by patching json de/serializer

redbeat/redbeat/decoder.py

Lines 94 to 102 in 8ebd5e0

if isinstance(obj, crontab):
return {
'__type__': 'crontab',
'minute': obj._orig_minute,
'hour': obj._orig_hour,
'day_of_week': obj._orig_day_of_week,
'day_of_month': obj._orig_day_of_month,
'month_of_year': obj._orig_month_of_year,
}

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

3 participants