Skip to content

Api: Add background task queue#78

Merged
kennethmyhra merged 1 commit into
incendilabs:mainfrom
losol:feature/background-task-queue
May 20, 2026
Merged

Api: Add background task queue#78
kennethmyhra merged 1 commit into
incendilabs:mainfrom
losol:feature/background-task-queue

Conversation

@losolio
Copy link
Copy Markdown
Contributor

@losolio losolio commented May 17, 2026

Plumbing a new IBackgroundTaskQueue. No consumers wired up in this slice; the $archive-import PR will be the first user.

Copilot AI review requested due to automatic review settings May 17, 2026 19:36
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

Adds the initial API-side plumbing for an in-process background task queue that can run queued work items through a hosted service with per-item DI scopes.

Changes:

  • Introduces IBackgroundTaskQueue and a Channel-backed implementation.
  • Adds QueuedHostedService to drain queued work items and isolate each item in a DI scope.
  • Registers the queue/hosted service in Program.cs and adds unit tests for execution, scoped resolution, and failure isolation.

Reviewed changes

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

Show a summary per file
File Description
src/Ignis.Api/Program.cs Registers the background task queue and hosted drainer.
src/Ignis.Api/Services/BackgroundTasks/IBackgroundTaskQueue.cs Defines the queue contract for producers and the hosted consumer.
src/Ignis.Api/Services/BackgroundTasks/BackgroundTaskQueue.cs Implements the queue with an unbounded single-reader channel.
src/Ignis.Api/Services/BackgroundTasks/QueuedHostedService.cs Runs queued delegates one at a time inside scoped service providers.
tests/Ignis.Api.Tests/BackgroundTaskQueueTests.cs Adds coverage for queued execution, scoped service resolution, and resilience after failures.

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

Comment thread src/Ignis.Api/Services/BackgroundTasks/BackgroundTaskQueue.cs Outdated
Comment thread src/Ignis.Api/Services/BackgroundTasks/QueuedHostedService.cs Outdated
@losolio losolio force-pushed the feature/background-task-queue branch from bdbaa51 to 462e5e4 Compare May 17, 2026 19:54
@losolio losolio requested a review from kennethmyhra May 17, 2026 20:14
Comment thread src/Ignis.Api/Services/BackgroundTasks/IBackgroundTaskQueue.cs Outdated
@losolio losolio force-pushed the feature/background-task-queue branch from 462e5e4 to d315a0e Compare May 19, 2026 20:29
/// its own DI scope so scoped services resolve outside the request.
/// </summary>
public sealed class QueuedHostedService(
BackgroundTaskQueue queue,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a fan of primary constructors, it messes up naming conventions for member variables. Just wasted time looking for the variable queue which is actually a member variable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I see your point. Our editorconfig actually states that we prefer primary ctors. I have changed to traditional constructors now, and suggest that we clean up other services with the same pattern, and change .editorconfig.

// Async scope so IAsyncDisposable scoped services dispose properly.
await using var scope = scopeFactory.CreateAsyncScope();
// CT.None: don't abort in-progress imports on shutdown.
await workItem(scope.ServiceProvider, CancellationToken.None).ConfigureAwait(false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How long-running is a workItem? Would a workItem be the whole import operation, or just a tiny chunk of it? If the former, I think maybe a hosted service might not be the right choice, but that is something we can decide on in the future, not now, just making this comment to make a mental note for the both of us.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, my thought was that the complete import would be one workitem, I guess it will take a few minutes. I agree that this has some drawbacks, however it will get us started on imports in an upcoming PR, but agree on the mental note on this.

Introduces IBackgroundTaskQueue. No consumers wired up in this slice;
the $archive-import PR will be the first user.
@losolio losolio force-pushed the feature/background-task-queue branch from d315a0e to 4014b46 Compare May 19, 2026 22:23
@kennethmyhra kennethmyhra merged commit d30a7ec into incendilabs:main May 20, 2026
5 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.

3 participants