Skip to content

feat: add first due scheduling - #9

Merged
gmaiyani merged 2 commits into
mainfrom
feat/add-first-due-scheduling-implementation
Nov 25, 2026
Merged

gmaiyani merged 2 commits into
mainfrom
feat/add-first-due-scheduling-implementation

Conversation

@gmaiyani

@gmaiyani gmaiyani commented Nov 17, 2026 •

Copy link
Copy Markdown

Summary

Add opt-in first-due scheduling and managed entry lifecycle support. Applications can select initial deadlines, update task definitions without shifting existing timing, and apply scheduling-policy changes while preserving pending work.

Changes

First-due scheduling

  • Add save_with_first_due() to persist an application-selected first deadline together with the definition, run metadata, policy fingerprint and entry identity.
  • Normalize timezone-aware deadlines to UTC while preserving fractional precision.
  • Add update_definition() to update task payloads without changing their stored deadline or pending immediate-run state.
  • Support first_run_kwargs for the first outgoing invocation without modifying recurring task arguments.

Lifecycle handling

  • Add the optional redbeat_entry_policy callback to adopt, change or remove scheduling policy during reservation. Policy changes affect the following run without moving the invocation already selected.
  • Add request_run() for delayed or urgent refresh requests. Overlapping requests retain the earliest pending deadline and latest payload.
  • Allow refreshes to preserve pending first-run context without restoring context already consumed.
  • Add save_guarded() and creation identities to reject stale writes after deletion and recreation under the same key.
  • Raise EntryAlreadyExists when concurrent creation finds an existing winning entry.
  • Protect managed writes against concurrent payload, policy and run-state changes, with three total attempts for Redis WATCH conflicts.
  • Avoid rewriting unchanged definitions during normal managed reservations and definition updates.

Compatibility and scope

  • Applications remain responsible for calculating offsets and defining lifecycle policy. RedBeat does not introduce a jitter configuration flag or application-specific scheduling rules.
  • Entries without managed state or policy adoption retain their ordinary scheduling path.
  • Explicit deadlines require timezone-aware datetimes and positive, non-relative interval schedules.
  • Managed Redis Cluster timing transactions require redis-py 6.1 or later and involved keys in the same hash slot.
  • Full-precision due checks prevent early publication, but deadlines do not guarantee exact dispatch or worker execution times.

Test coverage

  • Add unit and isolated Redis integration coverage for initial deadlines, fractional timing, first-run arguments and recurring execution.
  • Cover policy adoption, changes and removal, overlapping refresh requests, concurrent creation and updates, stale reservations, and deletion/recreation.
  • Cover bounded conflict retries, write efficiency, legacy persistence compatibility and authenticated Redis Cluster operations.
  • Add real broker/worker coverage for first-invocation context and recurrence.
  • Update CI to run pytest on Python 3.9–3.13 with an explicitly installed Redis test binary.

…tes (#7)

- Add save_with_first_due() to persist an exact first due time together with matching metadata, definition and an opaque policy fingerprint.
- Add update_definition() to update task payloads without moving their
stored due time.
- Support optional first_run_kwargs for the first outgoing invocation.
- Protect managed reservations and definition updates against conflicting
- Redis writes, changed state and deletion.
- Preserve newer payloads and immediate requests.
- Add unit and isolated Redis, Beat and worker integration test
- Add optional jitter settings for Helm and Docker Compose
- Calculate stable SHA-256 offsets for recurring WALK and POLL schedules
- Preserve fractional timestamps and normal polling intervals
- Keep stored next dues unchanged during policy transitions
- Apply enable, disable and window changes to the following run
- Preserve inventory refresh delays and immediate recovery requests
- Recover schedules using existing first-run rules before adopting jitter
- Protect managed updates against concurrent writes and schedule replacement
- Add regression coverage and document behavior and known limitations
- handle concurrent schedule creation safely
- Add EntryAlreadyExists to distinguish creation conflicts from invalid input
- Assign entry identity only after a successful Redis write
- Reuse bounded WATCH retries for first-due creation
@gmaiyani
gmaiyani marked this pull request as ready for review November 18, 2026 07:13
@gmaiyani
gmaiyani requested a review from ajasnosz November 18, 2026 07:16
Comment thread .github/workflows/ci.yml
Comment on lines +31 to 33
# Python 3.9 builds are available for Ubuntu 24.04, not 26.04.
os: [ubuntu-24.04]
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can move from python 3.9? it is not supported for long time

@gmaiyani
gmaiyani merged commit b3964bb into main Nov 25, 2026
6 checks passed
@gmaiyani
gmaiyani deleted the feat/add-first-due-scheduling-implementation branch November 25, 2026 06:08
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