Skip to main content

Module jobs

Module jobs 

Source
Expand description

Jobs: the application’s background work, folded from the job events its host publishes on the pop.job.event point (ADR 0010), each typed by a JobEventKind. egui-pop never runs jobs and never polls for them: the host publishes, Jobs follows, and the views (bars, the status bar, the jobs centre) draw what it holds. The table names each kind by the label it is journaled under; the model reads the kind, never a name.

Experimental: may change in any release (docs/stability.md).
Kind (journal label)Data
job.startedid, title, kind, badge (a symbol before the title, JobBadge), parent, weight (its share of its parent), total (none: indeterminate), steps ([{id, title, weight}] or names), cancellable (true), pausable (false), retryable (true), owner (the plugin the job runs for), command (the command that started it)
job.progressid, done, total, failed, skipped, item (the current item), item_progress (0 to 1), phase, step (the current step), step_done, step_total, estimate (the host’s own fraction, 0 to 1), badge (null takes it away)
job.item_failedid, item, error (the job goes on)
job.paused, job.resumedid
job.cancellingid, reason (why, when it was not the user)
job.failedid, error
job.finishedid, actions ([{title, command, args}])
job.cancelledid, reason (why, when it was not the user)
job.orphanedid, plugin, reason (published by egui-pop: the job’s plugin is disconnected and the job goes on)
job.adoptedplugin, jobs (their ids; published by egui-pop: the plugin is back and its orphaned jobs are its own again)
job.logid, text (lines of the job’s log)

A job has an owner when its job.started names one: owner, the plugin it runs for, or command, the command that started it; a job naming neither belongs to the plugin that published it, when its events’ source is a plugin. When that plugin is disconnected (ADR 0028, Jobs::left_by) a job naming it that can be cancelled is cancelled through the host’s job.cancel, with the reason (Job::reason); any other is kept and marked orphaned (Job::orphaned, from job.orphaned) until it ends, starts again or its plugin is back (Jobs::adopt). An orphaned job can be dismissed while it goes on: nothing may ever end it.

A job.started for a job already known starts it again (a retry): its progress is reset, its log kept, its finished children forgotten.

Forgetting a job (Jobs::dismiss, Jobs::clear_finished, the history’s trim) takes it and its ended descendants away; a descendant still going on is kept and becomes a top-level job (its parent cleared), so it stays in sight and ends on its own. A job forgotten leaves a tombstone, kept TOMBSTONE_SECS seconds (by the events’ clock) and at most TOMBSTONES of them: an event for it arriving late (a progress, a log line, its end) is dropped rather than making the job up again; a job.started for it is a new run and lifts the tombstone.

Every job carries an estimated overall fraction (Job::fraction, 0 to 1), or none while it cannot estimate (indeterminate):

  • a job with sub-steps (declared steps, and child jobs naming it as parent) rolls them up, each weighted by its estimate (weight, 1 by default): finished steps count whole, the current one by its own progress, the others nothing. A parent with a total counts its children not started yet at weight 1 each;
  • otherwise done of total, the current item’s progress included;
  • otherwise the host’s estimate;
  • otherwise none: the job is indeterminate until one of these comes, and once determinate it never goes back (its last estimate stays);
  • Jobs::refine overrides it (the application’s jobs.estimate hook, ADR 0011).

Time left (Job::eta) comes from the rate of that fraction, an exponential moving average over the times events arrived at, given by an injected clock (now): it is not given before ETA_AFTER seconds.

Cancel, pause, resume and retry are commands the host runs (job.cancel, job.pause, job.resume, job.retry, each with { "id" }): the model follows their command.dispatched and command.failed events too, so a job shows “cancelling” from the moment it was asked until the host says it is cancelled, and a refused request says why.

use egui_pop_model::jobs::{Incoming, JobEventKind, JobState, Jobs};
use serde_json::json;

let mut jobs = Jobs::new();
let mut at = |seq, kind, data: serde_json::Value, now| {
    jobs.apply(&Incoming::new(seq, kind, &data), now);
};
at(1, JobEventKind::Started, json!({ "id": "export", "title": "Export", "total": 4 }), 0.0);
at(2, JobEventKind::Progress, json!({ "id": "export", "done": 1, "item": "a.raw" }), 1.0);
let job = jobs.get("export").unwrap();
assert_eq!(job.state, JobState::Running);
assert_eq!(job.fraction, Some(0.25));
assert_eq!(job.item.as_deref(), Some("a.raw"));

Structs§

Incoming
An event as the model reads it.
ItemError
An item that failed.
Job
A job, as the events made it.
JobAction
A command a finished job offers (“Show in folder”).
JobBadge
A symbol drawn before a job’s title (the node a remote job runs on, a state): a registry icon’s name (phosphor:hard-drives), its tone, and its tooltip, which is also its accessible name, so a screen reader hears what the symbol means. Given by job.started or job.progress as badge:
Jobs
The jobs, folded from the journal.
Left
The jobs a disconnected plugin left (Jobs::left_by).
Step
A declared sub-step of a job.
Summary
All jobs at a glance.

Enums§

JobEventKind
What a job event says: the kind the host gives when it publishes the event on pop.job.event (egui-pop-api’s JobEvents). The model folds events by this kind, never by a journal entry’s name; name (job.started…) is only the label the event is journaled under.
JobState
Where a job is.
Request
Something asked of the host about a job, waiting for its answer.

Constants§

ADOPTED
The plugin of orphaned jobs is back: { "plugin", "jobs": [ids] } (published by egui-pop, not by the host).
CANCELLED
CANCELLING
Cancelling was accepted; the job winds down.
CMD_CANCEL
The commands the host runs on a job, each with { "id" }.
CMD_PAUSE
CMD_RESUME
CMD_RETRY
ETA_AFTER
Time left is not given before a job ran this long (seconds).
FAILED
FINISHED
HISTORY
How many finished jobs are kept by default.
ITEM_ERRORS
How many failed items a job keeps.
ITEM_FAILED
One item failed; the job goes on.
LOG
Lines of a job’s log.
LOG_LINES
How many lines of a job’s log are kept by default.
ORPHANED
The job’s plugin is disconnected and the job goes on (published by egui-pop, not by the host).
PAUSED
PROGRESS
A job moved on.
RESUMED
STARTED
A job started (or started again).
TOMBSTONES
How many forgotten jobs are remembered by default, to drop their late events.
TOMBSTONE_SECS
How long (seconds) a forgotten job is remembered by default.