API reference — Scheduling
Nuvora.Nexus.Relay.Scheduling.EfCore
EF Core (PostgreSQL) scheduled-message store for Nuvora Nexus Relay
dotnet add package Nuvora.Nexus.Relay.Scheduling.EfCore
Nuvora.Nexus.Relay.Scheduling.EfCore
EfCoreRecurringScheduleRepository<TContext>
public sealed class EfCoreRecurringScheduleRepository<TContext> : IRecurringScheduleRepository where TContext : DbContext
EF Core (PostgreSQL) recurring-schedule repository. The processor path claims one due schedule at a time with FOR UPDATE SKIP LOCKED inside a transaction, enqueues the planned occurrences as one-shot ScheduledMessage rows on the same context, and advances the schedule — so a given occurrence is enqueued once even across instances.
Constructors
EfCoreRecurringScheduleRepository(IDbContextFactory<TContext> contextFactory)
Methods
Task UpsertAsync(RecurringSchedule schedule, CancellationToken cancellationToken = default(CancellationToken))
Inserts the schedule, or merges it into the existing row with the same name. On an existing row the persisted RecurringSchedule.NextFireAt and RecurringSchedule.Enabled are preserved unless the cadence (cron expression / time zone) changed: re-registration on redeploy must neither skip occurrences missed during downtime (the catch-up policy handles them) nor re-enable an operator-paused schedule.
Task<Guid?> EnqueueImmediateAsync(string name, DateTimeOffset now, CancellationToken cancellationToken = default(CancellationToken))
Enqueues a single immediate one-shot delivery of the schedule’s message (used by TriggerNowAsync). Returns the new scheduled-message id, or null if the schedule is unknown.
Task<IReadOnlyList<RecurringSchedule>> ListAsync(CancellationToken cancellationToken = default(CancellationToken))
Task<RecurringSchedule?> GetAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
Task<bool> RemoveAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
Task<bool> SetEnabledAsync(string name, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
Task<int> ProcessDueAsync(DateTimeOffset now, int batchSize, Func<RecurringSchedule, RecurringPlan> plan, CancellationToken cancellationToken = default(CancellationToken))
Claims due schedules and, for each, enqueues the occurrences produced by plan and advances RecurringSchedule.NextFireAt atomically. Returns the number of occurrences enqueued.
EfCoreSchedulerRepository<TContext>
public sealed class EfCoreSchedulerRepository<TContext> : ISchedulerRepository where TContext : DbContext
EF Core (PostgreSQL) scheduler repository. On the write path, EfCoreSchedulerRepository.ScheduleAsync stages a row on the shared command DbContext (so it commits with the work that scheduled it). On the processor path, claiming/status updates use short-lived contexts from an IDbContextFactory and a FOR UPDATE SKIP LOCKED claim so multiple instances never deliver the same message. Mirrors EfCoreOutboxRepository.
Constructors
EfCoreSchedulerRepository(IRelayDbContextAccessor accessor, IDbContextFactory<TContext> contextFactory, IOptions<SchedulerProcessorOptions> options, IRetryPolicy? retryPolicy = null)
Methods
Task MarkExecutedAsync(Guid id, CancellationToken cancellationToken = default(CancellationToken))
Mark a claimed message as delivered.
Task ScheduleAsync(ScheduledMessage message, CancellationToken cancellationToken = default(CancellationToken))
Stage a scheduled message on the ambient transaction (not flushed here).
Task<DateTimeOffset?> GetNextDueAtAsync(CancellationToken cancellationToken = default(CancellationToken))
The next time any pending message becomes due, or null when none are pending. Lets the processor sleep exactly until the next due time instead of polling blindly.
Task<IReadOnlyList<ScheduledMessage>> ClaimDueAsync(int batchSize = 100, CancellationToken cancellationToken = default(CancellationToken))
Atomically claim up to batchSize due messages: Pending rows whose GREATEST(scheduled_for, next_attempt_at) is due, plus Processing rows whose claim has expired (stranded by a crash). Claimed rows are marked Processing with a fresh lease.
Task<IReadOnlyList<ScheduledMessage>> GetFailedAsync(int batchSize = 100, CancellationToken cancellationToken = default(CancellationToken))
Dead-lettered rows for inspection.
Task<IReadOnlyList<ScheduledMessage>> GetUpcomingAsync(int batchSize = 100, CancellationToken cancellationToken = default(CancellationToken))
Upcoming (not-yet-delivered) scheduled messages ordered by effective due time, for operator dashboards. Returns Pending rows only (both already-due and future), oldest-due first.
Task<ScheduledFailureOutcome> RecordFailureAsync(Guid id, string errorMessage, int maxRetries, CancellationToken cancellationToken = default(CancellationToken))
Record a delivery failure against the live row (backoff + dead-letter at the cap). A no-op returning ScheduledFailureOutcome.NotFound when the row is no longer Processing — e.g. it was cancelled while in-flight and must not be resurrected.
Task<SchedulerBacklog> GetBacklogAsync(CancellationToken cancellationToken = default(CancellationToken))
Aggregate depth counters for health checks and gauges.
Task<bool> DiscardFailedAsync(Guid id, CancellationToken cancellationToken = default(CancellationToken))
Permanently discard (delete) a dead-lettered scheduled message. False when not found / not failed.
Task<bool> RequeueFailedAsync(Guid id, CancellationToken cancellationToken = default(CancellationToken))
Requeue a dead-lettered message for immediate delivery. False when not found / not failed.
Task<int> CancelAsync(Guid id, CancellationToken cancellationToken = default(CancellationToken))
Cancel a single not-yet-delivered message. Returns rows affected (0 if already terminal).
Task<int> CancelByCorrelationAsync(Guid correlationId, CancellationToken cancellationToken = default(CancellationToken))
Cancel all not-yet-delivered messages for a correlation id (e.g. a saga’s timeouts).
Task<int> CancelByKeyAsync(string cancellationKey, CancellationToken cancellationToken = default(CancellationToken))
Cancel all not-yet-delivered messages for a cancellation key.
Task<int> DeleteCompletedAsync(DateTimeOffset olderThan, CancellationToken cancellationToken = default(CancellationToken))
Delete executed/cancelled rows older than the cut-off (maintenance). Returns rows deleted.
Nuvora.Nexus.Relay.Scheduling.EfCore.DependencyInjection
RecurringSchedulerServiceCollectionExtensions
public static class RecurringSchedulerServiceCollectionExtensions
Registration helpers for the EF Core (PostgreSQL) recurring-schedule repository.
Methods
static IServiceCollection AddRelayRecurringSchedulingEfCore<TContext>(this IServiceCollection services)
Registers the EF Core recurring-schedule repository bound to TContext. Requires an IDbContextFactory and the host context to call ApplyRelayScheduler() and ApplyRelayRecurringSchedules() in OnModelCreating.
SchedulerServiceCollectionExtensions
public static class SchedulerServiceCollectionExtensions
Registration helpers for the EF Core (PostgreSQL) scheduler repository.
Methods
static IServiceCollection AddRelaySchedulerEfCore<TContext>(this IServiceCollection services)
Registers the EF Core scheduler repository bound to TContext. Requires an IDbContextFactory (for the processor’s independent connections), the event-store accessor (AddRelayEventStoreEfCore), and the host context to call ApplyRelayScheduler() in OnModelCreating.
Nuvora.Nexus.Relay.Scheduling.EfCore.Persistence
RecurringScheduleModelBuilderExtensions
public static class RecurringScheduleModelBuilderExtensions
Maps the RecurringSchedule entity onto the host context’s model.
Methods
static ModelBuilder ApplyRelayRecurringSchedules(this ModelBuilder modelBuilder)
Applies the relay_recurring_schedules table mapping. Call from the host context’s OnModelCreating alongside ApplyRelayScheduler().
SchedulerModelBuilderExtensions
public static class SchedulerModelBuilderExtensions
Maps the scheduler table (relay_scheduled_messages) onto the host’s DbContext. Call from OnModelCreating so scheduling writes share the command’s transaction.
Methods
static ModelBuilder ApplyRelayScheduler(this ModelBuilder modelBuilder)