Skip to content

Add QueueDeleted event to IQueue<T> for queue deletion notifications#447

Merged
niemyjski merged 2 commits intomainfrom
feature/queue-deleted-event
Feb 6, 2026
Merged

Add QueueDeleted event to IQueue<T> for queue deletion notifications#447
niemyjski merged 2 commits intomainfrom
feature/queue-deleted-event

Conversation

@niemyjski
Copy link
Member

Summary

  • Adds a \QueueDeleted\ async event to \IQueue\ that is raised after a queue is deleted via \DeleteQueueAsync, enabling behaviors and event handlers to react to queue deletion (e.g., cleanup, logging, cache invalidation)
  • Refactors \DeleteQueueAsync\ into the base class using the \DeleteQueueImplAsync\ pattern (consistent with other queue operations), moving trace logging into the base so all implementations benefit
  • Wires the new event into \QueueBehaviorBase\ and updates queue documentation with examples

Changes

  • **\IQueue.cs**: Add \QueueDeleted\ event property and \QueueDeletedEventArgs\ class
  • **\QueueBase.cs**: Implement \OnQueueDeletedAsync, refactor \DeleteQueueAsync\ with \DeleteQueueImplAsync\ pattern, add trace logging, dispose the event
  • **\InMemoryQueue.cs**: Rename \DeleteQueueAsync\ override to \DeleteQueueImplAsync, remove duplicate trace logging (now in base)
  • **\QueueBehaviour.cs**: Wire \QueueDeleted\ event handler in \QueueBehaviorBase.Attach\
  • **\queues.md**: Document the new event in interface listing, events section, and behavior examples
  • **\InMemoryQueueTests.cs**: Add tests for event firing and behavior invocation

Test plan

  • All 1782 existing tests pass (0 failures)
  • New test: \DeleteQueueAsync_WithEventHandler_RaisesQueueDeletedEvent\ verifies event fires with correct args
  • New test: \DeleteQueueAsync_WithAttachedBehavior_InvokesBehaviorOnQueueDeleted\ verifies behavior hook invocation

Made with Cursor

Adds a QueueDeleted async event raised after a queue is deleted via DeleteQueueAsync. This enables behaviors and event handlers to react to queue deletion (e.g., cleanup, logging, cache invalidation).

- Add QueueDeletedEventArgs<T> and QueueDeleted event to IQueue<T>
- Implement OnQueueDeletedAsync in QueueBase with parallel invocation
- Refactor DeleteQueueAsync into base class with DeleteQueueImplAsync pattern
- Move trace logging from InMemoryQueue to QueueBase for all implementations
- Wire QueueDeleted into QueueBehaviorBase for behavior support
- Dispose QueueDeleted event in QueueBase.Dispose
- Update queue documentation with QueueDeleted event and behavior examples

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Contributor

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 new queue-deletion lifecycle event so queue consumers/behaviors can react after a queue is deleted, and refactors deletion into QueueBase for consistent behavior across implementations.

Changes:

  • Adds QueueDeleted async event to IQueue<T> and introduces QueueDeletedEventArgs<T>.
  • Refactors DeleteQueueAsync into QueueBase via a new DeleteQueueImplAsync override point, and raises QueueDeleted after deletion.
  • Updates QueueBehaviorBase<T>, docs, and in-memory queue tests to cover the new event.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Foundatio.Tests/Queue/InMemoryQueueTests.cs Adds tests asserting QueueDeleted is raised and behaviors are invoked on delete.
src/Foundatio/Queues/QueueBehaviour.cs Hooks QueueDeleted into QueueBehaviorBase<T>.Attach.
src/Foundatio/Queues/QueueBase.cs Implements DeleteQueueAsync in base, adds QueueDeleted event + invocation + disposal.
src/Foundatio/Queues/InMemoryQueue.cs Updates in-memory implementation to override DeleteQueueImplAsync and removes duplicate logging.
src/Foundatio/Queues/IQueue.cs Extends IQueue<T> with QueueDeleted and adds the new event args type.
docs/guide/queues.md Documents the new event and behavior override example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 419 to 422
queue.QueueDeleted.AddHandler(async (sender, args) =>
{
_logger.LogInformation("Queue deleted");
});
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

This example uses an async lambda with no await, which will produce a compiler warning in real code. Consider removing async (return Task.CompletedTask) or adding an awaited operation so the snippet is warning-free.

Copilot uses AI. Check for mistakes.
Remove async keyword from event handler lambdas that have no await, replacing them with synchronous lambdas that return Task.CompletedTask. Also fix Enqueuing handler to use args.Data instead of args.Entry.Value.

Co-authored-by: Cursor <cursoragent@cursor.com>
@niemyjski niemyjski merged commit d1a1981 into main Feb 6, 2026
4 checks passed
@niemyjski niemyjski deleted the feature/queue-deleted-event branch February 6, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments