Skip to content

Cratis Chronicle jobs: inspect and control

Cratis Chronicle jobs track long-running Kernel operations, such as replaying an observer or retrying a failed partition. Use the jobs API to find out whether that work is progressing before deciding to stop, resume, or request its deletion. An observer is the component that processes events for a projection, reducer, or reactor.

The examples use the .NET client and a connected IEventStore; follow the .NET connection guide if you need one. Jobs are scoped to that event store and namespace, so check both when a job you expect is missing. Stop, resume, and delete require authorization for administrator operations.

Start by listing jobs in the selected scope. Use each job’s Type and Details to identify the operation, then keep its Id for subsequent requests.

using Cratis.Chronicle;
using Cratis.Chronicle.Jobs;
public class JobsIndexListAll(IEventStore eventStore)
{
public async Task<IEnumerable<Job>> GetAllJobs() => await eventStore.Jobs.GetJobs();
}

View C# snippet source on GitHub

Read Status alongside Progress: the progress includes total, successful, failed, and stopped step counts. CompletedSuccessfully and CompletedWithFailures describe different outcomes; a job that has finished may still need investigation.

Fetch the job again when you need its current state:

using Cratis.Chronicle;
using Cratis.Chronicle.Jobs;
public class JobsIndexGetOne(IEventStore eventStore)
{
public async Task<Job?> GetJob(JobId jobId) => await eventStore.Jobs.GetJob(jobId);
}

View C# snippet source on GitHub

GetJob returns null when the job is absent from the selected scope. Check for that before reading its properties or fetching its steps.

When the overall status does not explain where work has stopped, inspect the individual steps. Each step has a Status, status-change history, and Progress with a percentage and message.

using Cratis.Chronicle;
using Cratis.Chronicle.Jobs;
public class JobsIndexGetSteps(IEventStore eventStore)
{
public async Task<IEnumerable<JobStep>?> GetSteps(JobId jobId)
{
var job = await eventStore.Jobs.GetJob(jobId);
return job is null ? null : await job.GetJobSteps();
}
}

View C# snippet source on GitHub

Compare successive reads to see whether progress changes. A single response describes the state at that moment; it does not keep updating as the job runs.

Stop pauses a running job so it can be resumed later. Resolve the cause of a failure before requesting more processing. Delete requests removal of the job and its associated steps; completed and failed jobs cannot be removed through this operation.

The following methods show the three separate requests, not a sequence to run against the same job:

using Cratis.Chronicle;
using Cratis.Chronicle.Jobs;
public class JobsIndexStopResumeDelete(IEventStore eventStore)
{
public async Task StopJob(JobId jobId) => await eventStore.Jobs.Stop(jobId);
public async Task ResumeJob(JobId jobId) => await eventStore.Jobs.Resume(jobId);
public async Task DeleteJob(JobId jobId) => await eventStore.Jobs.Delete(jobId);
}

View C# snippet source on GitHub

The wrappers above discard the results of Stop and Resume. In application code, inspect the returned JobCommandResult: Accepted tells you whether the request was taken, and Refusal explains why it was not. Awaiting the call alone does not establish that the job stopped or resumed.

Fetch the job and its steps again to check the resulting state. After a resume, follow progress through to the final status and check the affected read model or handler output. After a delete request, list jobs again to confirm removal.

For a failed observer or partition, continue with Operating Chronicle to diagnose the cause and choose a recovery. Recovering from failures explains when to retry existing state and when to replay history, including the risk of repeating external effects.

For event delivery to an external HTTP endpoint, see Webhooks.