Skip to content

respect last_run_at on save#313

Open
diaxoaine wants to merge 1 commit intosibson:mainfrom
diaxoaine:main
Open

respect last_run_at on save#313
diaxoaine wants to merge 1 commit intosibson:mainfrom
diaxoaine:main

Conversation

@diaxoaine
Copy link
Copy Markdown

@diaxoaine diaxoaine commented Apr 26, 2026

Updating an existing entry that has already run recalculates the schedule score with the last_run_at = now(), while still keeping the old last_run_at in the meta. The entry ends up waiting a full schedule cycle before firing again.

Current behaviour:

I have this hourly task

from redbeat import RedBeatSchedulerEntry
interval = celery.schedules.schedule(run_every=3600)
entry = RedBeatSchedulerEntry('task-name', 'tasks.some_task', interval, args=['args'])
entry.save()

The last run was 45 mins ago, so it will run in 15 mins from now. And now I update its args:

entry = RedBeatSchedulerEntry('task-name', 'tasks.some_task', interval, args=['new'])
entry.save()

the score is now 1 hour from now, instead of 15 mins.

Expected behaviour:

The score should still be 15 mins from now, since only the args changed.

@sibson
Copy link
Copy Markdown
Owner

sibson commented Apr 27, 2026

Your creating a new task, not updating the existing one. Use entry = RedBeatSchedulerEntry.from_key(), to update an existing entry

@diaxoaine
Copy link
Copy Markdown
Author

Your creating a new task, not updating the existing one. Use entry = RedBeatSchedulerEntry.from_key(), to update an existing entry

I'd say RedBeatSchedulerEntry(...) + save() already behaves like an upsert because entry's name is unique.

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

Successfully merging this pull request may close these issues.

2 participants