Skip to content

Fix missing DelayQueue key tracking in register_task#1116

Open
S0nee wants to merge 1 commit intomagicblock-labs:masterfrom
S0nee:DB&&DelayQueue
Open

Fix missing DelayQueue key tracking in register_task#1116
S0nee wants to merge 1 commit intomagicblock-labs:masterfrom
S0nee:DB&&DelayQueue

Conversation

@S0nee
Copy link
Copy Markdown

@S0nee S0nee commented Mar 29, 2026

Summary

register_task inserted tasks into DelayQueue without storing their keys in task_queue_keys.

This broke cancellation and update logic:

  • tasks could not be removed from the queue
  • duplicate tasks could appear on re-registration

Changes:

  • store queue key on insert:
let key = self.task_queue.insert(...);
self.task_queue_keys.insert(task.id, key);
  • remove existing task before re-registering
  • update unregister_task to also remove from DelayQueue

Result:

  • consistent queue - key mapping
  • correct cancel/update behavior
  • no duplicate or orphaned tasks

Compatibility

  • No breaking changes
  • Config change (describe):
  • Migration needed (describe):

Testing

  • tests (or explain)

Checklist

  • docs updated (if needed)
  • closes #

Summary by CodeRabbit

  • Refactor
    • Improved internal task scheduling queue management and database consistency handling to streamline the cancellation and registration processes.

… DelayQueue

Context

`unregister_task` previously removed a task only from the database, and from the `DelayQueue` only via `process_cancel_request`.
This made the API incomplete and could lead to desynchronization and “zombie tasks.”

Changes
`unregister_task:`
now accepts `&mut self`
removes the task from both the DelayQueue and the database
the duplicate `remove_task_from_queue` has been removed from process_cancel_request
the fallback (if the task is not in the database) has been preserved
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3cc0a148-b4f1-4355-87e8-6369d7f5a290

📥 Commits

Reviewing files that changed from the base of the PR and between 2c7cc3e and c20ed5f.

📒 Files selected for processing (1)
  • magicblock-task-scheduler/src/service.rs

📝 Walkthrough

Walkthrough

The service module refactors task removal and queue management logic. The unregister_task method signature is updated to take a mutable reference (&mut self instead of &self), and now performs both in-memory delay queue removal and database cleanup in a single operation. The register_task method is modified to remove any existing queue entry before inserting a new task, storing the returned DelayQueue key for future removal. Cancel handling is simplified to call unregister_task implicitly, eliminating redundant standalone queue removal calls.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant