Skip to content

Read a running job's progress

st, err := cluster.Observer().Get(ctx, job)
if err != nil {
    return err
}

latest := st.Submissions[len(st.Submissions)-1]
if st.State != dispatch.StateRunning || latest.Canonical == nil {
    return nil
}

r := cluster.Observer().(dispatch.ProgressReader)

p, err := r.Progress(ctx, *latest.Canonical)
switch {
case errors.Is(err, dispatch.ErrUnsupported):
    return nil // the adapter reads no beat
case err != nil:
    return err
case p.Seen.IsZero():
    return nil // no beat: no launcher, and no evidence of anything
case !p.Judged:
    fmt.Printf("step %d (%s), seen %s, not judged\n", p.Step, p.Phase, p.Seen.Format(time.TimeOnly))
default:
    fmt.Printf("step %d (%s), seen %s, stale %v\n", p.Step, p.Phase, p.Seen.Format(time.TimeOnly), p.Stale)
}

This reads the beat a launcher such as go/launch publishes for the running submission's object, and prints where the run has got to. Progress isn't part of Status: it is read on demand, never stored, and changes no record.

Get the reader

A Cluster's Observer is always a dispatch.ProgressReader, so the type assertion holds for any cluster built by dispatch.Open or dispatch.Compose. An adapter that reads no beat answers every call with dispatch.ErrUnsupported, naming itself. Progress needs no record store, so a read-only cluster reads it too.

Name the object

Progress takes the object's ref, the current submission's Canonical in its status. A ref the adapter can't find, such as a purged object's, is dispatch.ErrNotFound.

Read Judged before Stale

The adapter judges staleness on its own clock, and only once it has held a reading of the object's beat for the beat's staleAfter, 120 seconds from go/launch. A one-shot reader, such as a status command, therefore always answers Judged false: show "not judged" rather than "not stale". A long-lived reader, such as a supervisor's backend, sees Stale once the beat stops changing for staleAfter while the object runs.

Stale is no evidence for any state or cause: the job is still Running.