Progress#

Live progress display for orchestrator drains.

A drain runs a queue of jobs. On an interactive terminal it can show how far the sweep has got, the elapsed time and an estimated time remaining. The estimate is based on the jobs that actually executed, so a sweep that mostly reuses cached results does not overstate how long is left.

The display degrades gracefully. rich is used when it is importable, a plain ANSI line otherwise, and nothing at all when the output is not a terminal. There is no hard dependency on any third-party package.

class krum.orchestration.progress.Failure(key: str, params: Mapping[str, Any], error: str, path: Path | None = None)[source]#

Bases: object

What a failed job needs to be diagnosed from the console.

Carries the job’s identity, the parameters it ran with, the folder its traceback was written to, and the traceback itself.

error: str#
key: str#
params: Mapping[str, Any]#
path: Path | None#
class krum.orchestration.progress.NullProgress[source]#

Bases: object

A progress display that renders nothing.

advance(*, ran: bool, rerun: bool = False, duration: float = 0.0, description: str = '') → None[source]#

No-op.

close() → None[source]#

No-op.

describe(description: str = '') → None[source]#

No-op.

fail(failure: Failure) → None[source]#

No-op.

class krum.orchestration.progress.Progress(*args, **kwargs)[source]#

Bases: Protocol

A live progress display for a single drain.

advance(*, ran: bool, rerun: bool = False, duration: float = 0.0, description: str = '') → None[source]#

Record one completed job.

Parameters:
  • ran – Whether the job actually executed, as opposed to being reused from the cache.

  • rerun – Whether the job is being retried after a previous failed attempt.

  • duration – How long the job took to execute, in seconds. Ignored when ran is false.

  • description – A short label for the job just finished.

close() → None[source]#

Finish the display, leaving the terminal in a clean state.

describe(description: str = '') → None[source]#

Show a job about to start, without advancing the counter.

fail(failure: Failure) → None[source]#

Record the job that stopped the drain.

krum.orchestration.progress.describe_params(params: Mapping[str, Any], limit: int | None = 80) → str[source]#

Render a job’s parameters as a k=v · k=v string.

Class values are shortened to their qualified name, and the whole string is capped so a wide sweep does not fill the terminal. Pass limit=None to keep every parameter, which is what a failure report does.

krum.orchestration.progress.make_progress(total: int, runs_total: int, *, stream: TextIO | None = None) → Progress[source]#

Build the best display writing to stream, or a no-op without one.

Parameters:
  • total – The number of jobs in the drain.

  • runs_total – How many of them will actually execute, the rest being reused from the cache.

  • stream – The stream to draw on, as returned by progress_stream(). None disables the display.

Returns:
  • A no-op without a stream, a rich bar when ``rich`` is importable, and a

  • plain ANSI line otherwise.

krum.orchestration.progress.progress_stream(enabled: bool | TextIO) → TextIO | None[source]#

The stream a display would draw on, or None when it would draw nothing.

True means the default stream, standard error, and only when it is a terminal: a sweep whose output is redirected gets no escape codes. A stream passed explicitly is always drawn on, since asking for one is the point.