Jobs and progress
egui-pop never runs an application’s background work. The host (ADR
0010) runs it and publishes job events on egui-pop’s pop.job.event
point, each typed by a JobEventKind; egui-pop folds
them into a model, draws them, and sends the user’s requests back to the
host as commands. The design notes and the survey behind this page are
in Advanced widgets, section 3.
The jobs model
egui_pop::model::jobs::Jobs (no egui) folds the events into jobs;
JobsPlugin (opt-in, egui_pop::api::jobs) keeps it behind the JOBS
service, as a listener on the bus
(ADR 0029): the bus delivers each job
event once, in journal order, to the listeners of pop.job.event
(each pass, and before a wait or a plugin’s disconnection reads the
jobs: AppHandle::deliver_events), and pop.jobs.model is one of them.
Nothing polls: without new events, nothing is read.
The host publishes with a JobPublisher (Send + Sync, any thread):
the application hands one to its host (Host::set_job_publisher), and
AppHandle::job_publisher or AppHandle::publish_job give the same.
Each event is recorded in the journal under its kind’s label (the
table’s names, job.started…) for the journal’s readers, but the model
follows the point only: a journal entry merely named job.started is
not a job event, so a host never has to carry egui-pop’s names.
Asking about a job is a request on the bus: pop.job.cancel, pop.job.pause,
pop.job.resume, pop.job.retry (AppHandle::request_job with a
bus::JobAsk, or jobs::ask). Their listeners run in the call, in
their declared order: pop.jobs.model marks the job as waiting for the
answer, then pop.jobs.host runs its command for the host (or the
application’s runner); the answer is the host’s events. With no jobs
plugin, nobody listens and the request is refused (job.refused). The
order is printed by AppHandle::bus_order_of(&bus::JOB_POINTS) and kept
as a reviewed file (crates/egui-pop-api/tests/bus/jobs-points.txt).
| Kind (journal label) | Data |
|---|---|
job.started | id, title, kind, badge ({icon, tone, tip}: a registry symbol before the title, its tip its tooltip and accessible name), parent, weight, total (none: indeterminate), steps ([{id, title, weight}]), cancellable (true), pausable (false), retryable (true), owner (the plugin it runs for), command (the command that started it) |
job.progress | id, done, total, failed, skipped, item, item_progress (0 to 1), phase, step, step_done, step_total, estimate (the host’s own fraction), badge (null takes it away) |
job.item_failed | id, item, error (the job goes on) |
job.paused, job.resumed | id |
job.cancelling | id, reason (why, when it was not the user) |
job.failed | id, error |
job.finished | id, actions ([{title, command, args}]: “Show in folder”) |
job.cancelled | id, reason (why, when it was not the user) |
job.orphaned | id, plugin, reason (from egui_pop, not the host: the job’s plugin is disconnected and the job goes on) |
job.adopted | plugin, jobs (from egui_pop: the plugin is back, these jobs are no longer orphaned) |
job.log | id, text (lines of the job’s log) |
A job.started for a job already known starts it again (a retry): its
progress is reset, its log kept, its finished children forgotten.
Every job carries an estimated overall percentage (Job::fraction,
0 to 1, Job::percent), or none while it cannot estimate:
- a job with sub-steps rolls them up, each weighted by its estimate: its
declared
steps(a render: decode 1, process 3, write 1) and its child jobs (parent, each with itsweight). Finished parts count whole, the current one by its own progress, the others nothing; a batch with atotalcounts its children not started yet; - otherwise
doneoftotal, the current item’s progress included; - otherwise the host’s
estimate; - otherwise the job is indeterminate until it can estimate, and once determinate it never goes back (a growing total moves the bar back instead);
- the application refines it with a hook on the
jobs.estimatestep (ADR 0011).
Time left (Job::eta) follows the rate of that fraction (a moving
average over the times events arrived), never before 3 seconds, never
while paused. “Now” comes from the plugin’s clock: the motion clock by
default (below), a ManualClock of the test’s own if it wants
(JobsPlugin::clock).
use egui_pop::api::App;
use egui_pop::api::bus::JobEventKind;
use egui_pop::api::jobs::{JOBS, JobsPlugin};
use serde_json::json;
let mut app = App::builder()
.plugin(JobsPlugin::default())
.build(&egui_pop::egui::Context::default())
.unwrap();
let h = app.handle().clone();
// What a host publishes, from its own job facts.
h.publish_job("host", JobEventKind::Started, json!({
"id": "render", "title": "Render",
"steps": [
{ "id": "decode", "weight": 1 },
{ "id": "process", "weight": 3 },
{ "id": "write", "weight": 1 },
],
}));
h.publish_job("host", JobEventKind::Progress, json!({
"id": "render", "step": "process", "step_done": 1, "step_total": 2,
}));
app.logic(&egui_pop::egui::Context::default());
let render = h.service(&JOBS).unwrap().job("render").unwrap();
// Decode done (1), half of process (1.5), of 5.
assert_eq!(render.percent(), Some(50.0));
Cancel, pause, resume, retry
They are commands the host runs, each with { "id" }: job.cancel,
job.pause, job.resume, job.retry. JobsPlugin declares them for
the host (Ctx::declare), or runs them in-process with a runner the
application gives (JobsPlugin::run_locally). jobs::ask(app, id, request) runs one as the user and marks the job: it shows “cancelling”
from the moment it was asked until the host publishes job.cancelled;
a refused command leaves the reason in Job::request_error. The model
follows the commands’ command.dispatched and command.failed events,
so a request from an agent or a script shows the same way.
A job’s owner, and what happens when it goes
A job belongs to a plugin when its job.started names it: owner (the
plugin’s id) or command (a command the plugin declared, the one that
started the job). A job naming neither belongs to the plugin that
published it, when the events’ source is a plugin’s id; a host’s job
naming no one has no owner. Job::owner and Job::command keep them.
When the plugin is disconnected
(ADR 0028), each of
its jobs still going on gets one of two ends, both on the bus: the
plugin’s disconnection is a request (pop.plugin.disconnect) asked before
plugin.disconnected is said, and its listener
pop.jobs.cancel-on-disconnect asks them (Jobs::left_by decides, the
model follows the events as for any other):
- a job naming it that is
cancellableis cancelled by the host: the framework runsjob.cancelwith{ "id", "reason" }(sourcescript:egui_pop,reason“its pluginxis disconnected”). The job shows “cancelling” until the host publishesjob.cancelled, and keeps the reason (Job::reason); a host that refuses leavesJob::request_erroras for any request; - any other (not cancellable, or published by the plugin itself, which
will never end it) is kept and marked orphaned:
job.orphanedwith thepluginand thereason,Job::orphaned. The jobs centre says “running, its plugin x is off” and offers Dismiss on it though it goes on (Jobs::dismissaccepts an orphaned job). The mark goes when the job ends or starts again, or when the plugin reconnects (job.adopted, said bypop.jobs.adopt-on-connect, a listener ofpop.plugin.connect). An orphaned job is not waited on: nothing owns it and it may never end, soJobs::idle(and the application’ssettled) leave it out, andJobs::orphanslists it apart. Thejobscollector saysorphaned(a count) besideidle, andbridge.waitanswers it too: an agent sees the job without waiting on it. With only orphaned jobs going on, the status bar’s ring stays still (a spinning ring asks for a repaint each pass, so the application would never settle).
A child job follows its parent. plugin.disconnected counts both ends
(jobs_cancelled, jobs_orphaned), and each is an info line in the
log. Without the jobs plugin nothing is done: nothing follows jobs.
The jobs.estimate step
| Step | Arguments | Result |
|---|---|---|
jobs.estimate | id, title, kind, fraction (the model’s own, null while it cannot), done, total, steps, step, elapsed | { "fraction": 0 to 1 }, or the model’s own (or null) to leave it to the model |
It runs only when a plugin hooks it, once per pass for each active job that moved, so a job’s progress does not double the journal.
use egui_pop::prelude::*;
use egui_pop::api::jobs::STEP_ESTIMATE;
struct ScanEstimate;
impl Plugin for ScanEstimate {
fn id(&self) -> PluginId {
PluginId::from_static("scan_estimate")
}
fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
// A scan cannot count what is left; a library holds about 500
// folders.
ctx.replace(STEP_ESTIMATE, |_, args| {
if args["kind"] != "scan" || !args["fraction"].is_null() {
return Ok(serde_json::json!({ "fraction": args["fraction"] }));
}
let done = args["done"].as_f64().unwrap_or(0.0);
Ok(serde_json::json!({ "fraction": (done / 500.0).min(0.95) }))
});
Ok(())
}
}
let _ = ScanEstimate;
Agents and tests
The debug bridge’s jobs collector shows every job (state, fraction,
counts, time left, the end of its log), idle, what an agent waits
for (no owned job going on), and orphaned, the jobs going on that a
disconnected plugin left, which it does not wait for; its actions cancel, pause, resume, retry, dismiss and
clear do what the buttons do, for the user (devtools). They write, so
the bridge’s agent is refused them: it runs the job.cancel,
job.pause, job.resume and job.retry commands instead
(Agents).
egui_pop_test::jobs::FakeHost is a host whose jobs a test scripts,
event by event, without threads; it answers the job commands now, later
(until release) or never (Answer::Refuse):
let host = FakeHost::new();
host.answer(Answer::Later);
let mut app = App::builder().host(host.clone()).plugin(JobsPlugin::default())
.build(&ctx).unwrap();
host.job("export").start("Export", Some(4)).item(1, "a.raw").fail("disk full");
The motion clock
Spinners, travelling bars, shimmer and the busy delay read the motion
clock (egui_pop::core::motion), not the input’s time directly:
motion::now(ctx): the interface’s time, or a clock the application or a test gives (set_clock,freeze). A given clock moves only when told: a test freezes motion, steps it, and gets the same frames on every run. The jobs model reads the same clock, so a job’s start and a busy indicator’s delay agree;motion::phase(ctx, period, still): where a looping animation is (0 to 1);stillunder reduced motion (motion.durationis 0), so animated widgets give still frames;motion::animate(ctx): asks for the next frame of an animation on screen, never at once (a headless harness settles), four a second while the window is not focused, never under reduced motion or a given clock;motion::Busy: the delayed busy indicator. Nothing shows beforemotion.spinner.delay(300 ms): most work ends sooner, and a flash of spinner reads as a glitch. Once shown it staysmotion.spinner.min(500 ms), so it does not flash off. The delay counts from when the work started (a job’s or a command’s start), not from when the widget was first drawn, so a panel opened midway shows the right state at once; the frame where the indicator appears is asked for, no timer thread runs.
| Token | Default | What |
|---|---|---|
motion.spinner.delay | 300 ms | work shorter than this shows no busy indicator |
motion.spinner.min | 500 ms | a busy indicator, once shown, stays this long |
motion.spinner.turn | 900 ms | one turn of a spinner |
motion.progress.travel | 1500 ms | an indeterminate bar’s segment crossing its track |
motion.skeleton.shimmer | 1600 ms | a skeleton’s shimmer crossing it |
use egui_pop::core::motion::{self, Busy};
let ctx = egui_pop::egui::Context::default();
// In a test: motion stands still until told.
let clock = motion::freeze(&ctx, 0.0);
let busy = Busy::new(egui_pop::egui::Id::new("export"), 0.0);
clock.set(0.2);
assert!(!busy.visible(&ctx, true));
clock.set(0.4);
assert!(busy.visible(&ctx, true));
Progress widgets
egui_pop::core::progress draws progress from a fraction; the jobs
centre and the status bar feed them a job’s estimate. They are drawn by
the kit (kit.md): progress-bar and progress-line (the
tracks), progress-fill (fills and sections, by tone),
progress-caption, meter and meter-tick, progress-ring and
spinner (colours only), on the motion clock. The former progress.*
tokens are no longer read (see the changelog’s migration table).
| Widget | What |
|---|---|
ProgressBar | determinate (new(Some(f)), counts(done, total)) or indeterminate (new(None): a segment travelling along the track; a still striped track under reduced motion); tones (Tone::Accent while running, Info, Success, Warning, Danger, Muted when paused); stacked sections after the fill (failed, skipped); line() for the thin line; caption(true) draws the name and the value text above it |
Ring | a small circle: an arc from the top, or a turning arc when indeterminate |
Meter | a value against thresholds (disk space, memory), its tone the highest threshold reached; AccessKit role Meter. As a value bar in a slot: size(vec2) fills it, vertical() fills it from the bottom (a level meter, vertical for assistive technologies too) |
Spinner | a turning arc with a label; delayed(id, since, busy) shows it only after motion.spinner.delay and keeps it motion.spinner.min, its space kept while hidden |
Each is an AccessKit ProgressIndicator with its name (label); a
determinate one has a numeric value and its range (0 to the total with
counts, otherwise 0 to 100) and a value text (“340 of 1,204”, or the
text given); an indeterminate one has no value. Colour is never the
only signal: the state is in the name or the text.
use egui_pop::core::progress::{ProgressBar, Spinner, Tone};
fn ui(ui: &mut egui_pop::egui::Ui, started: f64, loading: bool) {
ui.add(
ProgressBar::counts(340, 1204)
.label("Importing photos")
.section(61.0 / 1204.0, Tone::Danger, "failed")
.text("340 of 1,204, 61 failed")
.caption(true),
);
ui.add(
Spinner::new()
.label("Loading thumbnails")
.delayed(egui_pop::egui::Id::new("thumbnails"), started, loading),
);
}
Busy controls and the status bar
A command the host answers later (Reply::Later) shows as running
until its result arrives (AppHandle::running, and
AppHandle::running_since, by the motion clock). Controls bound to it
show it:
egui_pop::api::busy::CommandButton: a button running a command, greyed while it waits; aftermotion.spinner.delaya spinner takes its icon’s place for at leastmotion.spinner.min. Its width and its name stay, AccessKit’sbusyflag is set, and a failed run says why on hover;- menu items bound to the command do the same;
- a status bar indicator (
strips::IndicatorState::busy, the time the work started) shows a delayed spinner before its text; JobsPluginadds the status bar’s jobs item: a ring with the jobs’ overall estimate (turning while one cannot estimate), “Jobs: 3 (42%)”, and “Failed: 1”; nothing while there is nothing to say.
use egui_pop::api::AppHandle;
use egui_pop::api::busy::CommandButton;
use egui_pop::core::icon::Icon;
use egui_pop::model::ids::CommandId;
fn toolbar(ui: &mut egui_pop::egui::Ui, app: &AppHandle) {
ui.add(CommandButton::new(app, CommandId::from_static("doc.export")).icon(Icon::Save));
}
The jobs centre
egui_pop::api::jobs_centre draws every job the host runs, the same
list in two places: the Jobs panel (declared by JobsPlugin,
closed until asked for; without_panel() leaves it out) and a
popover from the status bar’s jobs item.
- Each job: a chevron, its title and state, a bar of its estimated overall percentage (failed and skipped items stacked after the fill), the percentage, “n of m”, the current step and item, the time left, the reason it failed or why the host refused a request, its failed items (folded), and buttons asking the host: Pause, Resume, Cancel, Retry; Dismiss forgets a finished one, its actions (“Show”) run their commands. A batch’s children fold under it. Finished jobs go to the history, cleared by hand (“Clear finished”).
- The chevron opens the job’s log console, collapsed by default and
remembered per job (
JobsService::expanded), so the panel, the popover and a toast agree. The console streams the job’sjob.loglines. - Buttons are named with their job for assistive technologies (“Cancel: Export 12 images”); the chevron says what it does (“Show the log of Export 12 images”).
- A toast can carry a job (
Toast::info("Exporting").job(id)): its bar, Cancel while it runs, its first action once it ended. It stays while the job goes on; closing it does not cancel the job.
Where the console comes from (layering). The jobs centre is part of
the application API (L3), which sits below egui-pop-editors (L4,
ADR 0001), so it cannot use the editors’ Terminal. It draws plain
lines (ANSI escapes dropped) by itself, and looks for a JOB_LOG_VIEW
service first: egui_pop::editors::JobConsolesPlugin provides one, a
Terminal over a Console source per job, fed the job’s new lines as
they come (colours, scrollback, selection, copy; with TerminalPlugin,
agents read it as the terminal job:<id>). The facade offers it with
its editors feature; an application without the editors keeps the
plain console.
use egui_pop::prelude::*;
use egui_pop::api::jobs::JobsPlugin;
use egui_pop::editors::{JobConsolesPlugin, TerminalPlugin};
let app = App::builder()
.plugin(JobsPlugin::default())
.plugin(TerminalPlugin)
.plugin(JobConsolesPlugin)
.build(&egui_pop::egui::Context::default())
.unwrap();
let _ = app;
An application’s rows: row sources
Not all background work is a host job: an application may wait on
promises, keep links to other machines, or watch conditions. Instead of
a list of its own, it declares a row source, and the jobs centre
shows its rows beside the jobs (egui_pop::model::job_rows). The
source is on the bus, so nothing else needs to know it:
pop.jobs.rows(JobRowsSet, aJobRowsAsk) declares a source, or replaces its rows: its id, its title (the filter’s label), its owner, and every row it has now.pop.jobs.source.drop(JobSourceDrop) takes it away. Both may be asked from any thread on the bus the application holds (app.bus().alter::<JobRowsSet>(…)), or withAppHandle::request_job_rowsandrequest_job_source_drop.JobsPlugin’s listener (pop.jobs.sources) keeps them (JobsService::sources).- A plugin disconnected takes the sources it owns with it
(
job_sources_droppedinplugin.disconnected’s counts). - Each row (
JobRow): an id, a title, a state (queued,running,waiting,done,failed), its progress when it knows it (0 to 1: a bar), a detail line (also its tooltip), a registry symbol (JobBadge, its tip its accessible name), a group, and actions (RowAction:cancel,retryoropen, each a command run with its arguments; its label the kind’s unless it gives atitle). - The list shows each source’s rows under its title, ungrouped rows first, then each group under its name. The source decides when a row goes: the jobs centre keeps no history of them.
- Once a source is declared, a filter bar shows: a toggle per source
(egui-pop’s own jobs first,
OWN_SOURCE) and the states shown (all, active, done, failed);JobsService::filterandset_filterread and set it. Without a source, the list is as before, unfiltered. - Accessibility: each source’s rows are a list named by its title, each row a list item named “title, state” (“Sync with the NAS, waiting”), each action a button named with its row (“Retry: Sync with the NAS”); the filter bar is a toolbar (“Filter the jobs”), its source toggles check boxes (“Show Network”), its states radio buttons (“Show: Failed”).
use egui_pop::prelude::*;
use egui_pop::api::bus::JobRowsAsk;
use egui_pop::api::jobs::{JOBS, JobsPlugin};
use egui_pop::model::job_rows::{JobRow, RowAction, RowActionKind, RowState};
use serde_json::json;
let app = App::builder()
.plugin(JobsPlugin::default())
.build(&egui_pop::egui::Context::default())
.unwrap();
let h = app.handle();
h.request_job_rows(JobRowsAsk::new(
"nodes",
"Network",
"my_app",
vec![
JobRow::new("nas", "Sync with the NAS", RowState::Waiting)
.detail("The NAS is asleep")
.group("Machines")
.action(RowAction::new(RowActionKind::Retry, "nodes.wake").args(json!({ "node": "nas" }))),
],
));
assert_eq!(h.service(&JOBS).unwrap().sources()[0].rows.len(), 1);
The gallery’s Jobs page adds a demo source (“Add a row source”).
Skeletons and empty states
egui_pop::core::placeholder:
Skeletonstands in for content that fills progressively, in its layout:Skeleton::text(lines)for a paragraph,Skeleton::rows(n)for list rows (a block and two lines each). Shapes inskeleton.fill, a shimmer crossing them inskeleton.shimmereverymotion.skeleton.shimmer; no shimmer under reduced motion nor under a given motion clock, so tests get still frames. Its region carries AccessKit’sbusyflag and a name (“Loading the metadata”, “Loading” by default). Not for thumbnails: show what is known instead (an embedded preview, an average colour, as the thumbnail grid does).EmptyStatesays why a place is empty and what to do: an icon, a title, a sentence, an action (showreturns whether it was clicked; the application runs its command),danger()when something went wrong.
use egui_pop::core::icon::Icon;
use egui_pop::core::placeholder::{EmptyState, Skeleton};
fn queue(ui: &mut egui_pop::egui::Ui, rows: Option<&[String]>) -> bool {
match rows {
None => {
ui.add(Skeleton::rows(4).label("Loading the queue"));
false
}
Some([]) => EmptyState::new(Icon::Folder, "The queue is empty")
.text("Export images to fill it.")
.action("Export")
.show(ui),
Some(rows) => {
for r in rows {
ui.label(r);
}
false
}
}
}
Tests: crates/egui-pop-core/tests/placeholder.rs (a skeleton busy and
named, its height per line or row, a width kept, still under a given
clock; an empty state’s title, sentence and action, an unknown icon
drawn as the placeholder and reported).
Gaps
- A job with no event for a long time is not shown as “not responding” yet (the host would declare its timeout).
- Queued jobs (a position in a queue, reordering) are not modelled.