# IJobShard Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.durablejobs/orleans.durablejobs.ijobshard/)

## ConsumeDurableJobsAsync {#consumedurablejobsasync-a51f2335}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durablejobs/orleans.durablejobs.ijobshard/methods/consumedurablejobsasync-a51f2335/)

```csharp
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 {#getjobcountasync-3b1f284c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durablejobs/orleans.durablejobs.ijobshard/methods/getjobcountasync-3b1f284c/)

```csharp
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) {#markascompleteasync-system-threading-cancellationtoken-a5632e68}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durablejobs/orleans.durablejobs.ijobshard/methods/markascompleteasync-system-threading-cancellationtoken-a5632e68/)

```csharp
public abstract Task MarkAsCompleteAsync(CancellationToken cancellationToken)
```

Marks this shard as complete, preventing new jobs from being scheduled.

### Parameters

- `cancellationToken` (`CancellationToken`): A token to cancel the operation.

### Returns

A task that represents the asynchronous operation.

## RemoveJobAsync(string, CancellationToken) {#removejobasync-string-system-threading-cancellationtoken-7b636186}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durablejobs/orleans.durablejobs.ijobshard/methods/removejobasync-string-system-threading-cancellationtoken-7b636186/)

```csharp
public abstract Task<bool> RemoveJobAsync(string jobId, CancellationToken cancellationToken)
```

Removes a durable job from this shard.

### Parameters

- `jobId` (`string`): The unique identifier of the job to remove.
- `cancellationToken` (`CancellationToken`): 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) {#retryjoblaterasync-orleans-durablejobs-ijobruncontext-system-datetimeoffset-syst-049350d2}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durablejobs/orleans.durablejobs.ijobshard/methods/retryjoblaterasync-orleans-durablejobs-ijobruncontext-system-datetimeoffset-syst-049350d2/)

```csharp
public abstract Task RetryJobLaterAsync(IJobRunContext jobContext, DateTimeOffset newDueTime, CancellationToken cancellationToken)
```

Reschedules a job to be retried at a later time.

### Parameters

- `jobContext` (`IJobRunContext`): The context of the job to retry.
- `newDueTime` (`DateTimeOffset`): The new due time for the job.
- `cancellationToken` (`CancellationToken`): A token to cancel the operation.

### Returns

A task that represents the asynchronous operation.

## TryScheduleJobAsync(ScheduleJobRequest, CancellationToken) {#tryschedulejobasync-orleans-durablejobs-schedulejobrequest-system-threading-canc-76c266e6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durablejobs/orleans.durablejobs.ijobshard/methods/tryschedulejobasync-orleans-durablejobs-schedulejobrequest-system-threading-canc-76c266e6/)

```csharp
public abstract Task<DurableJob?> TryScheduleJobAsync(ScheduleJobRequest request, CancellationToken cancellationToken)
```

Attempts to schedule a new job on this shard.

### Parameters

- `request` (`ScheduleJobRequest`): The request containing the job scheduling parameters.
- `cancellationToken` (`CancellationToken`): 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.
