Skip to content

Adds scheduling support to Mocha#9467

Merged
PascalSenn merged 14 commits intomainfrom
pse/adds-messaging-scheduler
Mar 29, 2026
Merged

Adds scheduling support to Mocha#9467
PascalSenn merged 14 commits intomainfrom
pse/adds-messaging-scheduler

Conversation

@PascalSenn
Copy link
Copy Markdown
Member

@PascalSenn PascalSenn commented Mar 27, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 27, 2026 20:48
@github-actions github-actions Bot added the 📚 documentation This issue is about working on our documentation. label Mar 27, 2026
Copy link
Copy Markdown
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

This PR introduces first-class message scheduling in Mocha by propagating ScheduledTime through the dispatch pipeline, adding native scheduling behavior to supported transports, and providing a Postgres-backed scheduler for transports without native scheduling (e.g., RabbitMQ). It also updates documentation and performs minor punctuation cleanup across docs/examples.

Changes:

  • Add ScheduledTime to envelopes/dispatch context and wire it through PublishAsync/SendAsync/RequestAsync, plus convenience scheduling extensions.
  • Implement scheduling execution paths: native scheduling for InMemory + Postgres transport; store-based scheduling via EF Core Postgres (worker + dispatcher + store + EF interceptors).
  • Add extensive unit/integration test coverage and documentation for scheduling behavior.

Reviewed changes

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

Show a summary per file
File Description
website/src/docs/mocha/v1/scheduling.md New scheduling documentation (API + transport behavior + EF setup).
website/src/docs/mocha/v1/mediator/pipeline-and-middleware.md Doc punctuation cleanup (em dash → hyphen).
website/src/docs/mocha/v1/mediator/index.md Doc punctuation cleanup (em dash → hyphen).
website/src/docs/mocha/v1/hosting.md Doc punctuation cleanup (em dash → hyphen).
src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/SchedulingTests.cs Verifies RabbitMQ still delivers even when ScheduledTime is set (no native scheduling).
src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresMessageEnvelopeParserTests.cs Tests scheduled-time header parsing in Postgres envelope parser.
src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/SchedulingTests.cs Verifies Postgres transport defers/dispatches based on ScheduledTime.
src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/MessageStoreTests.cs Updates store method calls to include scheduled-time parameter.
src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/SchedulingTests.cs Verifies InMemory transport defers/dispatches based on ScheduledTime.
src/Mocha/test/Mocha.Tests/Transport/MessageEnvelopeWriterTests.cs Adds serialization/roundtrip tests for envelope scheduledTime.
src/Mocha/test/Mocha.Tests/Transport/MessageEnvelopeReaderTests.cs Adds parsing tests for envelope scheduledTime.
src/Mocha/test/Mocha.Tests/Scheduling/SchedulingMiddlewareIntegrationTests.cs Integration tests for scheduling middleware behavior (store/no store/skip flag).
src/Mocha/test/Mocha.Tests/Scheduling/SchedulingInterceptorTests.cs Tests EF Core interceptors that signal the scheduler on save/commit.
src/Mocha/test/Mocha.Tests/Scheduling/SchedulingDispatchContextExtensionsTests.cs Tests SkipScheduler() feature flag behavior.
src/Mocha/test/Mocha.Tests/Scheduling/MessageBusSchedulingExtensionsTests.cs Tests ScheduleSendAsync / SchedulePublishAsync convenience methods.
src/Mocha/test/Mocha.Tests/Scheduling/MessageBusSchedulerSignalTests.cs Tests scheduler signal sleep/wake and cancellation behavior.
src/Mocha/test/Mocha.Tests/Scheduling/DispatchSchedulingMiddlewareTests.cs Unit tests for dispatch scheduling middleware installation and persistence behavior.
src/Mocha/test/Mocha.Tests/Mocha.Tests.csproj Adds EF Sqlite + project refs needed for new scheduling tests.
src/Mocha/test/Mocha.Sagas.Tests/SagaSchedulingTests.cs Tests saga scheduling extensions produce options with ScheduledTime.
src/Mocha/test/Mocha.Sagas.Tests/Mocha.Sagas.Tests.csproj Adds TimeProvider testing package for saga scheduling tests.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresSchedulingIntegrationTests.cs Integration tests for EF/Postgres scheduled-message worker + dispatcher.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/Mocha.EntityFrameworkCore.Postgres.Tests.csproj Adds Mocha.Scheduling project reference.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/Helpers/TestDbContext.cs Registers scheduled-message EF model configuration.
src/Mocha/src/Mocha/Transport/MessageEnvelopeReader.cs Adds envelope scheduledTime serialization + parsing.
src/Mocha/src/Mocha/Transport/MessageEnvelope.cs Adds ScheduledTime property + JSON property constant.
src/Mocha/src/Mocha/Sagas/Descriptors/SagaTransitionDescriptorExtensions.cs Implements scheduled send/publish for saga transitions (was NotImplemented).
src/Mocha/src/Mocha/Sagas/Descriptors/SagaLifeCycleDescriptorExtensions.cs Implements scheduled send/publish for saga lifecycle actions (was NotImplemented).
src/Mocha/src/Mocha/Middlewares/DispatchContext.cs Adds ScheduledTime to dispatch context + reset behavior.
src/Mocha/src/Mocha/Middlewares/Dispatch/DispatchSerializerMiddleware.cs Ensures envelope includes ScheduledTime during serialization.
src/Mocha/src/Mocha/Middlewares/DefaultMessageBus.cs Wires options.ScheduledTime into dispatch context for publish/send/request.
src/Mocha/src/Mocha/MessageBusSchedulingExtensions.cs Adds ScheduleSendAsync/SchedulePublishAsync convenience methods.
src/Mocha/src/Mocha/Extensions/TimeProviderExtensions.cs Adds internal helper to resolve TimeProvider from DI with fallback.
src/Mocha/src/Mocha/Execution/PublishOptions.cs Updates PublishOptions.ScheduledTime doc comment.
src/Mocha/src/Mocha/Abstractions/Context/IDispatchContext.cs Adds ScheduledTime to dispatch context abstraction.
src/Mocha/src/Mocha.Transport.Postgres/PostgresMessagingTransport.cs Marks Postgres transport as natively supporting scheduling.
src/Mocha/src/Mocha.Transport.Postgres/PostgresMessageHeaders.cs Adds scheduledTime header constant.
src/Mocha/src/Mocha.Transport.Postgres/PostgresMessageEnvelopeParser.cs Parses scheduledTime header into envelope.
src/Mocha/src/Mocha.Transport.Postgres/PostgresDispatchEndpoint.cs Persists scheduled_time into message store + writes header.
src/Mocha/src/Mocha.Transport.Postgres/Mocha.Transport.Postgres.csproj Adds reference to Mocha.Scheduling.
src/Mocha/src/Mocha.Transport.Postgres/Connection/PostgresMessageStore.cs Adds scheduled-time parameter and inserts into scheduled_time column.
src/Mocha/src/Mocha.Transport.InMemory/Mocha.Transport.InMemory.csproj Adds reference to Mocha.Scheduling.
src/Mocha/src/Mocha.Transport.InMemory/InMemoryScheduler.cs Adds in-process scheduler loop for deferred dispatch.
src/Mocha/src/Mocha.Transport.InMemory/InMemoryMessagingTransport.cs Initializes/starts/stops scheduler; marks native scheduling support.
src/Mocha/src/Mocha.Transport.InMemory/InMemoryDispatchEndpoint.cs Defers dispatch to scheduler when ScheduledTime is in the future.
src/Mocha/src/Mocha.Scheduling/SchedulingTransportFeature.cs Adds feature flag for transport-native scheduling capability.
src/Mocha/src/Mocha.Scheduling/SchedulingMiddlewareFeature.cs Adds pooled feature to bypass scheduling middleware per dispatch.
src/Mocha/src/Mocha.Scheduling/SchedulingDispatchContextExtensions.cs Adds SkipScheduler() extension for dispatch context.
src/Mocha/src/Mocha.Scheduling/SchedulerCoreServiceCollectionExtensions.cs Registers scheduling core services + installs scheduling middleware.
src/Mocha/src/Mocha.Scheduling/Mocha.Scheduling.csproj New scheduling project.
src/Mocha/src/Mocha.Scheduling/MessageBusSchedulerSignal.cs Implements scheduler sleep/wake signal with capped delay.
src/Mocha/src/Mocha.Scheduling/ISchedulerSignal.cs Defines signal contract for waking the dispatcher.
src/Mocha/src/Mocha.Scheduling/IScheduledMessageStore.cs Defines scheduled-message persistence contract.
src/Mocha/src/Mocha.Scheduling/DispatchSchedulingMiddleware.cs Adds dispatch middleware that persists scheduled envelopes to store.
src/Mocha/src/Mocha.Scheduling/Assembly.cs InternalsVisibleTo for Mocha.Tests.
src/Mocha/src/Mocha.Mediator/MediatorMiddlewareFactoryContextExtensions.cs Doc punctuation cleanup (em dash → hyphen).
src/Mocha/src/Mocha.EntityFrameworkCore/Scheduling/SchedulingSaveChangesInterceptor.cs EF Core save-changes interceptor to notify scheduler.
src/Mocha/src/Mocha.EntityFrameworkCore/Scheduling/SchedulingEntityFrameworkCorePersistenceBuilderExtensions.cs Registers scheduling core + EF interceptors.
src/Mocha/src/Mocha.EntityFrameworkCore/Scheduling/SchedulingDbTransactionInterceptor.cs EF Core transaction-commit interceptor to notify scheduler.
src/Mocha/src/Mocha.EntityFrameworkCore/Mocha.EntityFrameworkCore.csproj Adds reference to Mocha.Scheduling.
src/Mocha/src/Mocha.EntityFrameworkCore/Assembly.cs InternalsVisibleTo for Mocha.Tests.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/SchedulingServiceCollectionExtensions.cs Registers Postgres scheduling pipeline (options/store/dispatcher/worker/hosted service).
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/ScheduledMessageWorker.cs Hosted service that runs the dispatcher loop with a dedicated connection.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/ScheduledMessageQueries.cs Builds SQL used by dispatcher/store (insert/poll/process/delete/update error).
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/ScheduledMessageDispatcher.cs Polls table and dispatches due messages through Mocha runtime with retries.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/ScheduledMessage.cs EF entity representing scheduled-message rows.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/PostgresScheduledMessagePersistenceModelBuilderExtensions.cs Adds model builder extension to register scheduled-message entity mapping.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/PostgresScheduledMessageOptions.cs Holds named connection/query options for scheduling.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/PostgresScheduledMessageEntityConfiguration.cs EF mapping for scheduled-message table + indexes.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Scheduling/EfCoreScheduledMessageStore.cs Raw-SQL persistence store used by scheduling middleware for EF/Postgres.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/ScheduledMessageTableInfo.cs Adds metadata structure for scheduled-message table/columns/index names.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/PostgresTableInfo.cs Extends table-info options with scheduled-message table metadata.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Outbox/OutboxProcessor.cs Improves envelope read logging and commit error handling.
src/Mocha/src/Mocha.EntityFrameworkCore.Postgres/Mocha.EntityFrameworkCore.Postgres.csproj Adds reference to Mocha.Scheduling.
src/Mocha/src/Examples/Transports/RabbitMQ/RabbitMQ.cs Comment punctuation cleanup (em dash → hyphen).
src/Mocha/src/Examples/MediatorShowcase/MediatorShowcase.cs Comment punctuation cleanup (em dash → hyphen).
src/Mocha/src/Examples/MediatorShowcase/Handlers.cs Log message punctuation cleanup (em dash → hyphen).
src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Internal/PoolingBenchmarks.cs Comment punctuation cleanup (em dash → hyphen).
src/Mocha/Mocha.slnx Adds Mocha.Scheduling project to solution.
src/All.slnx Adds Mocha.Scheduling project to aggregate solution.

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

Comment thread src/Mocha/src/Mocha.Scheduling/DispatchSchedulingMiddleware.cs Outdated
Comment thread website/src/docs/mocha/v1/scheduling.md Outdated
Comment thread src/Mocha/src/Mocha/MessageBusSchedulingExtensions.cs Outdated
@PascalSenn PascalSenn force-pushed the pse/adds-messaging-scheduler branch from 4fc0c91 to d8d3a9c Compare March 27, 2026 21:28
PascalSenn and others added 10 commits March 27, 2026 21:36
- Forward to next middleware when Envelope is null instead of silently
  dropping the message in DispatchSchedulingMiddleware
- Fix docs claiming TimeSpan overloads exist when only DateTimeOffset
  overloads are available on IMessageBus
- Fix XML docs on scheduling extensions to say "dispatch pipeline"
  instead of "transport" since messages may be persisted, not sent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants