Expand description
Jobs, as a plugin (JobsPlugin, opt-in): the host’s background
work, followed on the bus (ADR 0029). The host publishes
its job events on pop.job.event, each typed by a
JobEventKind (see egui_pop_model::jobs for their data), with
the JobPublisher the application hands
it (Host::set_job_publisher);
no journal entry is read by its name. The bus delivers each once, in
journal order, to the listeners of pop.job.event
(each pass, and before a read that must see them all), and the
Jobs model behind the JOBS service is one of them
(MODEL, pop.jobs.model): no job state changes but on a bus event or
request. Nothing polls: without events, nothing is read.
Experimental: may change in any release
(docs/stability.md).
- Every job carries an estimated overall fraction
(
Job::fraction): sub-steps and child jobs roll up, weighted by their estimates; a job that cannot estimate is indeterminate until it can. Thejobs.estimatestep (ADR 0011) lets an application refine it: a run-hook or an after-hook sees the job and gives{ "fraction": 0.4 }(ornull: the model’s own). It runs only when a plugin hooks it, once per pass for each job that moved, so a job’s progress does not double the journal. - Cancel, pause, resume and retry are requests on the bus
(
pop.job.cancel,pop.job.pause,pop.job.resume,pop.job.retry,AppHandle::request_job;askasks one):MODELmarks the job as waiting for the answer, thenHOSTruns its command (each{ "id" }), declared for the host to run, or run in-process by a runner the application gives (JobsPlugin::run_locally). The answer is the runner’s job events. - A job belongs to a plugin when its
job.startednames it (owner, orcommand, a command of the plugin), or when the plugin published it itself. When that plugin is disconnected (ADR 0028),CANCEL_ON_DISCONNECT(a listener ofpop.plugin.disconnect, run beforeplugin.disconnectedis said) asks the host to cancel its jobs that can be (job.cancelwith{ "id", "reason" }, fromegui_pop; the job keeps the reason,Job::reason) and publishesjob.orphanedfor the others, which go on, marked (Job::orphaned: the jobs centre says “its plugin is off”) until they end or the plugin is back (job.adopted, said byADOPT_ON_CONNECT, a listener ofpop.plugin.connect).plugin.disconnectedcounts both (jobs_cancelled,jobs_orphaned). An orphaned job is not waited on:JobsService::idleleaves it out (nothing owns it, it may never end) andJobsService::orphanslists it. - An application adds rows of its own, as row sources
(
egui_pop_model::job_rows): it askspop.jobs.rowswith a source’s every row (AppHandle::request_job_rows, or on the bus from any thread) andpop.jobs.source.dropto take it away; the plugin’s listener (JOB_SOURCES) keeps them (JobsService::sources) and the jobs centre shows them beside the jobs, filtered by source and state (JobsService::filter). A plugin disconnected takes the sources it owns with it (job_sources_droppedinplugin.disconnected’s counts). - Time left comes from the plugin’s clock (
JobsPlugin::clock), the motion clock by default (egui_pop_core::motion, frozen in tests); tests may give aManualClockof their own. - The debug bridge’s
jobscollector shows every job (state, fraction, counts, time left, the end of its log) and whether the application is idle; its actions ask the host as the buttons do.
use egui_pop_api::App;
use egui_pop_api::jobs::{JOBS, JobsPlugin};
use egui_pop_model::jobs::JobEventKind;
use serde_json::json;
let mut app = App::builder()
.plugin(JobsPlugin::default())
.build(&egui::Context::default())
.unwrap();
let h = app.handle().clone();
h.publish_job("host", JobEventKind::Started, json!({ "id": "export", "title": "Export", "total": 8 }));
h.publish_job("host", JobEventKind::Progress, json!({ "id": "export", "done": 2 }));
app.logic(&egui::Context::default());
let jobs = h.service(&JOBS).unwrap();
assert_eq!(jobs.job("export").unwrap().fraction, Some(0.25));
assert!(!jobs.idle());Structs§
- Jobs
Plugin - The plugin.
- Jobs
Service - The jobs, folded from the journal: what views and agents read.
Constants§
- ADOPT_
ON_ CONNECT - Of
pop.plugin.connect: the jobs a plugin had left are its own again (job.adopted). - CANCEL_
ON_ DISCONNECT - Of
pop.plugin.disconnect: the jobs a plugin leaves are cancelled, or said orphaned. - CMD_
CANCEL - CMD_
PAUSE - CMD_
RESUME - CMD_
RETRY - HOST
- Runs a job request’s command, after
MODEL: the host (or the application’s runner) answers with its events. - JOBS
- The jobs, as a service.
- MODEL
- The jobs model’s listener: of
pop.job.event(it folds each event), and of the job requests (the job shows as asked). - STEP_
ESTIMATE - A job’s estimate, refined by the application:
{ "id", "title", "kind", "fraction" (the model's own,nullwhile it cannot estimate), "done", "total", "steps", "step", "elapsed" }; the result is{ "fraction": 0 to 1 }, or the model’s own (ornull) to leave it to the model.
Functions§
- ask
- Asks the host to cancel, pause, resume or retry a job, on the bus
(
AppHandle::request_job): the job shows as waiting for the answer, and its command runs for whoever acts now. - command_
of - The command asking
request. - status_
text - What the status bar’s jobs item says: how many go on (with their overall estimate), and how many failed.
Type Aliases§
- Runner
- Runs a job command in-process: the application’s own job runner.