Skip to content

Add Redis scheduler backend with distributed leadership support#6

Merged
longzhi merged 4 commits into
mainfrom
feature/redis-scheduler-backend
Oct 2, 2025
Merged

Add Redis scheduler backend with distributed leadership support#6
longzhi merged 4 commits into
mainfrom
feature/redis-scheduler-backend

Conversation

@longzhi
Copy link
Copy Markdown

@longzhi longzhi commented Oct 1, 2025

Summary

  • Added a Redis-backed distributed scheduler backend with leadership coordination and Redis state persistence, including config builder, lock handling, and task synchronization logic (src/beat/backend.rs, src/beat/backend/redis.rs, src/beat/schedule/**).

  • Extended SchedulerBackend with optional distributed hooks; updated beat loop to honor distributed decisions while keeping legacy backends unchanged.

  • Introduced schedule descriptors, examples (examples/redis_beat.rs), documentation updates, and helper tests/config for multi-instance scenarios (README.md, pyproject.toml, src/beat/mod.rs).

Testing

cargo fmt
cargo check
AMQP_ADDR=amqp://localhost:5672 cargo test --lib
AMQP_ADDR=amqp://localhost:5672 cargo test --test codegen

Introduces a Redis-powered distributed scheduler backend (RedisSchedulerBackend) with leader election and state synchronization for scheduled tasks. Updates the beat loop to support distributed backends, adds schedule descriptors for serialization, and extends cron/interval schedule types for persistence. Includes a new example (redis_beat.rs) and updates documentation for usage.
Added leader and follower sleep hint logic to the RedisSchedulerBackend, ensuring more responsive failover and efficient scheduling. Updated documentation in README and beat module to clarify backend selection and failover testing. Also added a new TickDecision::execute_with_hint method for more flexible scheduling.
Added [project] section to pyproject.toml with project name, version, Python requirement, and dependencies on celery and redis. This sets up the initial project configuration for dependency management.
Copilot AI review requested due to automatic review settings October 1, 2025 09:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Redis-backed distributed scheduler functionality with leadership coordination for Celery beat instances. The implementation enables multiple beat instances to coordinate task scheduling through Redis, with automatic leader election and failover capabilities.

Key changes:

  • Added RedisSchedulerBackend with distributed leadership support via Redis locks
  • Extended the scheduler architecture with DistributedScheduler trait and optional hooks
  • Introduced schedule descriptors for serializing/deserializing schedule state in Redis

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/error.rs Added RedisError variant to handle Redis-specific errors
src/beat/schedule/mod.rs Extended Schedule trait with serialization support and added Any bound
src/beat/schedule/descriptor.rs New module for serializable schedule descriptors with roundtrip conversion
src/beat/schedule/cron/*.rs Added serialization support methods to cron time units and schedule
src/beat/mod.rs Updated beat loop to support distributed scheduling decisions
src/beat/backend/redis.rs Complete Redis backend implementation with leadership coordination
src/beat/backend.rs Added distributed scheduler traits and decision structures
examples/redis_beat.rs Example demonstrating Redis-backed beat usage
pyproject.toml Added Python dependencies for examples
README.md Updated documentation with Redis backend information
Cargo.toml Added Redis script feature and redis_beat example

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/beat/schedule/cron/mod.rs
Comment thread src/beat/backend/redis.rs
Comment thread src/beat/backend/redis.rs
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment thread src/beat/backend/redis.rs
Introduced a Redis-based scheduler backend with configurable lock management and task state persistence. Added documentation and examples for multi-instance beat deployments.
@longzhi longzhi merged commit 48c899a into main Oct 2, 2025
13 of 14 checks passed
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