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.
List all jobs
Section titled “List all jobs”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();}import io.cratis.chronicle.EventStore
suspend fun listJobs(store: EventStore) { store.jobs.getJobs().forEach { job -> println("${job.type}: ${job.status}") }}import Cratis.Chronicle.Contracts.Jobs.JobsOuterClass;
import io.cratis.chronicle.EventStore;
import io.cratis.chronicle.java.JobsServiceJavaBridge;
import java.util.List;
class JobsIndexListAll { void listJobs(EventStore store) { List<JobsOuterClass.JobSummaryResponse> jobs = JobsServiceJavaBridge.getJobs(store.getJobs()); for (JobsOuterClass.JobSummaryResponse job : jobs) { System.out.println(job.getType() + ": " + job.getStatus()); } }}defmodule MyApp.JobsIndexListAll do def get_all_jobs do Cratis.Chronicle.Jobs.all() endendimport { IEventStore } from '@cratis/chronicle';import { JobSummaryResponse } from '@cratis/chronicle.contracts';
class JobsIndexListAll { constructor(private readonly store: IEventStore) {}
async getAllJobs(): Promise<JobSummaryResponse[]> { return this.store.jobs.getJobs(); }}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.
Get a single job
Section titled “Get a single job”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);}import io.cratis.chronicle.EventStore
suspend fun getReindexJob(store: EventStore, jobId: String) { val job = store.jobs.getJob(jobId) if (job != null) { println("${job.type}: ${job.status}") }}import Cratis.Chronicle.Contracts.Jobs.JobsOuterClass;
import io.cratis.chronicle.EventStore;
import io.cratis.chronicle.java.JobsServiceJavaBridge;
class JobsIndexGetOne { void getReindexJob(EventStore store, String jobId) { JobsOuterClass.JobSummaryResponse job = JobsServiceJavaBridge.getJob(store.getJobs(), jobId); if (job != null) { System.out.println(job.getType() + ": " + job.getStatus()); } }}defmodule MyApp.JobsIndexGetOne do def get_job(job_id) do Cratis.Chronicle.Jobs.get(job_id) endendimport { IEventStore } from '@cratis/chronicle';import { JobSummaryResponse } from '@cratis/chronicle.contracts';
class JobsIndexGetOne { constructor(private readonly store: IEventStore) {}
async getJob(jobId: string): Promise<JobSummaryResponse | undefined> { return this.store.jobs.getJob(jobId); }}GetJob returns null when the job is absent from the selected scope. Check for that before reading its properties or fetching its steps.
Get the steps for a job
Section titled “Get the steps for a job”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(); }}import io.cratis.chronicle.EventStore
suspend fun listJobSteps(store: EventStore, jobId: String) { store.jobs.getJobSteps(jobId).forEach { step -> println("${step.name}: ${step.status}") }}import Cratis.Chronicle.Contracts.Jobs.JobsOuterClass;
import io.cratis.chronicle.EventStore;
import io.cratis.chronicle.java.JobsServiceJavaBridge;
import java.util.List;
class JobsIndexGetSteps { void listJobSteps(EventStore store, String jobId) { List<JobsOuterClass.JobStepSummaryResponse> steps = JobsServiceJavaBridge.getJobSteps(store.getJobs(), jobId); for (JobsOuterClass.JobStepSummaryResponse step : steps) { System.out.println(step.getName() + ": " + step.getStatus()); } }}defmodule MyApp.JobsIndexGetSteps do def get_steps(job_id) do Cratis.Chronicle.Jobs.steps(job_id) endendimport { IEventStore } from '@cratis/chronicle';import { JobStepSummaryResponse } from '@cratis/chronicle.contracts';
class JobsIndexGetSteps { constructor(private readonly store: IEventStore) {}
async getSteps(jobId: string): Promise<JobStepSummaryResponse[]> { return this.store.jobs.getJobSteps(jobId); }}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, resume, and delete
Section titled “Stop, resume, and delete”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);}import io.cratis.chronicle.EventStore
suspend fun controlJob(store: EventStore, jobId: String) { store.jobs.stop(jobId) store.jobs.resume(jobId) store.jobs.delete(jobId)}import io.cratis.chronicle.EventStore;
import io.cratis.chronicle.java.JobsServiceJavaBridge;
class JobsIndexControl { void controlJob(EventStore store, String jobId) { JobsServiceJavaBridge.stop(store.getJobs(), jobId); JobsServiceJavaBridge.resume(store.getJobs(), jobId); JobsServiceJavaBridge.delete(store.getJobs(), jobId); }}defmodule MyApp.JobsIndexStopResumeDelete do def stop_job(job_id), do: Cratis.Chronicle.Jobs.stop(job_id) def resume_job(job_id), do: Cratis.Chronicle.Jobs.resume(job_id) def delete_job(job_id), do: Cratis.Chronicle.Jobs.delete(job_id)endimport { IEventStore } from '@cratis/chronicle';
class JobsIndexStopResumeDelete { constructor(private readonly store: IEventStore) {}
async stopJob(jobId: string): Promise<void> { await this.store.jobs.stop(jobId); }
async resumeJob(jobId: string): Promise<void> { await this.store.jobs.resume(jobId); }
async deleteJob(jobId: string): Promise<void> { await this.store.jobs.delete(jobId); }}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.
Related topics
Section titled “Related topics”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.