Skip to main content

Module jobs

Module jobs 

Source
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. The jobs.estimate step (ADR 0011) lets an application refine it: a run-hook or an after-hook sees the job and gives { "fraction": 0.4 } (or null: 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; ask asks one): MODEL marks the job as waiting for the answer, then HOST runs 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.started names it (owner, or command, a command of the plugin), or when the plugin published it itself. When that plugin is disconnected (ADR 0028), CANCEL_ON_DISCONNECT (a listener of pop.plugin.disconnect, run before plugin.disconnected is said) asks the host to cancel its jobs that can be (job.cancel with { "id", "reason" }, from egui_pop; the job keeps the reason, Job::reason) and publishes job.orphaned for 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 by ADOPT_ON_CONNECT, a listener of pop.plugin.connect). plugin.disconnected counts both (jobs_cancelled, jobs_orphaned). An orphaned job is not waited on: JobsService::idle leaves it out (nothing owns it, it may never end) and JobsService::orphans lists it.
  • An application adds rows of its own, as row sources (egui_pop_model::job_rows): it asks pop.jobs.rows with a source’s every row (AppHandle::request_job_rows, or on the bus from any thread) and pop.jobs.source.drop to 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_dropped in plugin.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 a ManualClock of their own.
  • The debug bridge’s jobs collector 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§

JobsPlugin
The plugin.
JobsService
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, null while it cannot estimate), "done", "total", "steps", "step", "elapsed" }; the result is { "fraction": 0 to 1 }, or the model’s own (or null) 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.