Skip to content

Conversation

@longzhi
Copy link

@longzhi longzhi commented Oct 7, 2025

Summary

  • add a ResultBackend abstraction with Redis implementation for Celery-compatible task metadata storage
  • wire AsyncResult and task lifecycle hooks to persist states, propagate errors, and fetch results
  • document client usage, ship a redis_results example, and sync codegen/tests for the new backend

Testing

  • cargo test
  • cargo test --test integrations (fails: requires local Redis + AMQP brokers)

- Added RedisBackend struct to manage task metadata using Redis.
- Implemented methods to store, retrieve, and delete task metadata.
- Introduced configuration options for key prefix and result TTL.
- Added an in-memory backend for testing purposes.
- Included unit tests to verify functionality of the Redis backend.
Copilot AI review requested due to automatic review settings October 7, 2025 07:13
Copy link

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

Adds a Redis result backend feature for Celery-compatible task metadata storage, enabling task result persistence and retrieval with AsyncResult integration.

  • Add ResultBackend abstraction with Redis implementation for storing task states and results
  • Wire AsyncResult and task lifecycle hooks to persist states, propagate errors, and fetch results
  • Document client usage with examples and sync codegen/tests for the new backend functionality

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/backend/mod.rs Core result backend trait and task metadata structures
src/backend/redis.rs Redis implementation of the result backend
src/task/async_result.rs Enhanced AsyncResult with backend integration for result fetching
src/app/trace.rs Task lifecycle hooks to persist states via result backend
src/app/mod.rs CeleryBuilder integration for result backend configuration
examples/redis_results.rs Example demonstrating Redis result backend usage
tests/beat_codegen/mod.rs Updated codegen tests with error handling
tests/app_codegen/mod.rs Updated codegen tests with error handling
src/task/mod.rs ResultValue trait for task return type serialization
README.md Documentation updates for result backend feature

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

let key = self.key_for(&meta.task_id);

if let Some(ttl) = self.result_ttl {
conn.set_ex::<_, _, ()>(key, payload, ttl.as_secs()).await?;
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

Using ttl.as_secs() truncates sub-second precision. For TTL values less than 1 second, this will result in immediate expiration (0 seconds). Consider using set_ex with ttl.as_secs().max(1) or implement a more precise TTL handling approach.

Suggested change
conn.set_ex::<_, _, ()>(key, payload, ttl.as_secs()).await?;
conn.set_ex::<_, _, ()>(key, payload, ttl.as_secs().max(1)).await?;

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +81
let mut fallback = TaskMeta::success(self.task_id(), &()).unwrap();
fallback.result = Some(Value::String(format!("{:?}", returned)));
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

The fallback serialization using format!(\"{:?}\", returned) may not produce valid JSON and could lose type information. Consider using a more structured approach like wrapping the debug string in a JSON object with metadata about the serialization failure.

Copilot uses AI. Check for mistakes.
@longzhi longzhi merged commit 67aa210 into main Oct 7, 2025
7 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