Skip to content

JobShard Methods

Base implementation of IJobShard that provides common functionality for job shard implementations.

ConsumeDurableJobsAsync

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

Returns

An asynchronous enumerable of durable job contexts.

DisposeAsync

virtual
View source
public virtual ValueTask DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

Returns

A task that represents the asynchronous dispose operation.

GetJobCountAsync

View source
public 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)

View source
public 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)

View source
public 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)

View source
public 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)

View source
public 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.