Skip to content

IJobShard Methods

Represents a shard of durable jobs that manages a collection of jobs within a specific time range. A job shard is responsible for storing, retrieving, and managing the lifecycle of durable jobs that fall within its designated time window.

ConsumeDurableJobsAsync

abstract
public abstract IAsyncEnumerable<IJobRunContext> ConsumeDurableJobsAsync()
Consumes durable jobs from this shard in order of their due time.

Returns

An asynchronous enumerable of durable job contexts.

GetJobCountAsync

abstract
public abstract ValueTask<int> GetJobCountAsync()
Gets the number of jobs currently scheduled in this shard.

Returns

A task that represents the asynchronous operation. The task result contains the job count.

MarkAsCompleteAsync(CancellationToken)

abstract
public abstract Task MarkAsCompleteAsync(CancellationToken cancellationToken)
Marks this shard as complete, preventing new jobs from being scheduled.

Parameters

cancellationTokenCancellationToken
A token to cancel the operation.

Returns

A task that represents the asynchronous operation.

RemoveJobAsync(string, CancellationToken)

abstract
public abstract Task<DurableJobMutationResult> RemoveJobAsync(string jobId, CancellationToken cancellationToken)
Removes a durable job from this shard.

Parameters

jobIdstring
The unique identifier of the job to remove.
cancellationTokenCancellationToken
A token to cancel the operation.

Returns

A task containing the durable mutation outcome.

RescheduleJobAsync(IJobRunContext, DateTimeOffset, CancellationToken)

abstract
public abstract Task<DurableJobMutationResult> RescheduleJobAsync(IJobRunContext jobContext, DateTimeOffset newDueTime, CancellationToken cancellationToken)
Reschedules a successfully completed execution with its dequeue count reset.

Parameters

jobContextIJobRunContext
The context of the completed execution.
newDueTimeDateTimeOffset
The new due time for the job. This value supersedes DurableJob on IJobRunContext.
cancellationTokenCancellationToken
A token to cancel the operation.

Returns

A task containing the durable mutation outcome.

RetryJobLaterAsync(IJobRunContext, DateTimeOffset, CancellationToken)

abstract
public abstract Task<DurableJobMutationResult> RetryJobLaterAsync(IJobRunContext jobContext, DateTimeOffset newDueTime, CancellationToken cancellationToken)
Reschedules a job to be retried at a later time.

Parameters

jobContextIJobRunContext
The context of the job to retry.
newDueTimeDateTimeOffset
The new due time for the job. This value supersedes DurableJob on IJobRunContext.
cancellationTokenCancellationToken
A token to cancel the operation.

Returns

A task containing the durable mutation outcome.

TryScheduleJobAsync(ScheduleJobRequest, CancellationToken)

abstract
public abstract Task<DurableJob?> TryScheduleJobAsync(ScheduleJobRequest request, CancellationToken cancellationToken)
Attempts to schedule a new job on this shard.

Parameters

requestScheduleJobRequest
The request containing the job scheduling parameters.
cancellationTokenCancellationToken
A token to cancel the operation.

Returns

A task that represents the asynchronous operation. The task result contains the durable job if successful, or null if the job could not be scheduled (e.g., the shard was marked as complete).

Exceptions

System.ArgumentOutOfRangeException
Thrown when the due time is outside the shard's time range.

TryStartAttemptAsync(IJobRunContext, CancellationToken)

abstract
public abstract Task<DurableJobMutationResult> TryStartAttemptAsync(IJobRunContext jobContext, CancellationToken cancellationToken)
Attempts to reserve a dequeued durable job for execution.

Parameters

jobContextIJobRunContext
The dequeued job context.
cancellationTokenCancellationToken
A token to cancel the operation.

Returns

A task containing DurableJobMutationResult when the attempt may start, DurableJobMutationResult when cancellation or completion removed the job first, or DurableJobMutationResult when this shard is no longer locally owned.