Calculate next_run at every run for a Schedule Object

I have got a question about django-q, where I could not find any answers in its documentation.

Question: Is it possible to calculate the next_run at every run at the end?

The reason behind it: The q cluster does not cover local times with dst (daylight saving time).

As example:

  • A schedule that should run 6am. german time.
  • For summer time: The schedule should be executed at 4am (UTC).
  • For winter time: The schedule should be executed at 5am (UTC).

To fix that I wrote custom logic for the next run. This logic is taking place in the custom function.

I tried to retrieve the schedule object in the custom function and set the next_run there.

The probleme here is: If I put the next_run logic before the second section "other calculations" it does work, But if I place it after the second section "other calculations" it does not work. Other calculations are not related to the schedule object.

def custom_function(**kwargs)

    # 1. some calculations not related to schedule object

    # this place does work
    related_schedule= Schedule.objects.get(id=kwargs["schedule_id"])
    related_schedule.next_run = ... 
    related_schedule.save()

    # 2. some other calculations not related to schedule object

    # this place doesn't

That is very random behaviour which I could not explain to me.

Back to Top