# JobContext

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.jobcontext/
> Summary: JobContext: The context available during an IJobHandler execution.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The context available during an [IJobHandler](/api/tracon.ijobhandler/) execution.

```csharp
public sealed class JobContext
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.jobcontext/">JobContext</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

The handler does not access [IJobStore](/api/tracon.ijobstore/) directly; this keeps
the handler focused only on execution logic and removes the need to set
up a fake store in a unit test. It carries no service provider either:
the handler is built by the container from its own per-execution scope, so
its dependencies arrive through its constructor.

## Constructors

### <a id="Tracon_JobContext__ctor"></a> JobContext\(\)

```csharp
public JobContext()
```

## Properties

### <a id="Tracon_JobContext_IsCancelledAsync"></a> IsCancelledAsync

Checks whether the job was cancelled by an external request
(`POST .../cancel`). The handler supports cooperative
cancellation by checking this between items.

```csharp
public required Func<CancellationToken, ValueTask<bool>> IsCancelledAsync { get; init; }
```

#### Property Value

 [Func](https://learn.microsoft.com/dotnet/api/system.func\-2)<[CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken), [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>\>

#### Remarks

The built-in worker also cancels the handler's token within one
`TraconSchedulingOptions.PollInterval` of the cancel request, so a
handler that reads its token stops without asking. This check is the
immediate answer, read from the store.

### <a id="Tracon_JobContext_Items"></a> Items

The job's items, by sequence number. Carries every item, regardless of
[JobItemRecord.Status](/api/tracon.jobitemrecord/#Tracon_JobItemRecord_Status) — not filtered down to
[JobItemStatus.Pending](/api/tracon.jobitemstatus/) ones. On a retry (see
[IJobHandler.ExecuteAsync](/api/tracon.ijobhandler/#Tracon_IJobHandler_ExecuteAsync_Tracon_JobContext_System_Threading_CancellationToken_)'s remarks), items already
[JobItemStatus.Completed](/api/tracon.jobitemstatus/) or [JobItemStatus.Failed](/api/tracon.jobitemstatus/)
from an earlier attempt are present here too; the handler is
responsible for skipping them.

```csharp
public required IReadOnlyList<JobItemRecord> Items { get; init; }
```

#### Property Value

 [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[JobItemRecord](/api/tracon.jobitemrecord/)\>

### <a id="Tracon_JobContext_Job"></a> Job

The record of the job being executed.

```csharp
public required JobRecord Job { get; init; }
```

#### Property Value

 [JobRecord](/api/tracon.jobrecord/)

### <a id="Tracon_JobContext_ReportItemAsync"></a> ReportItemAsync

Reports an item's processing result. The handler must call this as
each item is processed; the result is reflected into the persistent
store and the job's counters.

```csharp
public required Func<JobItemResult, CancellationToken, ValueTask> ReportItemAsync { get; init; }
```

#### Property Value

 [Func](https://learn.microsoft.com/dotnet/api/system.func\-3)<[JobItemResult](/api/tracon.jobitemresult/), [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken), [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)\>
