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<bool> 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 that represents the asynchronous operation. The task result contains true if the job was successfully removed, or false if the job was not found.

RetryJobLaterAsync(IJobRunContext, DateTimeOffset, CancellationToken)

abstract
public abstract Task 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.
cancellationTokenCancellationToken
A token to cancel the operation.

Returns

A task that represents the asynchronous operation.

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.