protonfs.webui.jobs module¶
Background Drive work for du --gui: deduplicated breakdown jobs and one walk at a time.
Request threads never call Drive; they queue work here and the page hears the results as
events. Events are plain dicts carrying Python objects ({"event": "breakdown", "path": p,
"breakdown": <Breakdown>}); Api turns them into JSON.
Added in version 3.4.0.
- class protonfs.webui.jobs.JobQueue(engine, settings, workers=2, log=None)[source]¶
Bases:
objectRuns breakdown jobs on worker threads and one walk on its own thread.
Events published to subscribers (each a dict with an
"event"key):breakdown:pathand the finishedbreakdown(aBreakdown).trash:trash, the engine’s trash summary orNone(after a breakdown of/).progress:done,total,pathandstate(running,done,cancelledorerror), aggregated over every path of the walk. The last event of a walk is neverrunning; acancelledorerrorone keeps the last knowndoneandtotal(erroraddsmessage). The last event also carriesfailed: how many folders could not be measured (their subtrees were not walked).error:pathandmessagefor a job that raised, or for a folder a walk could not measure; the work carries on.
- Parameters:
engine (
UsageEngine) – the usage engine the jobs run on.settings (
Callable[[],GuiSettings]) – returns the currentGuiSettings; read at the start of every job, so live edits apply to the next job.workers (
int) – number of breakdown worker threads.log (
Optional[Callable[[str],None]]) – called with one line of text for each job queued, started, finished or failed, each walk start and end, each walk error and each notice;Nonefor no logging. Called from any thread.
A subscriber whose queue holds
MAX_BACKLOGunread events is dropped: its queue receives a finalNoneafter the backlog is discarded.Added in version 3.4.0.
- close()[source]¶
Stop the workers and end every subscriber’s stream (a
Noneis queued to each).- Return type:
- notify(message)[source]¶
Publish
{"event": "notice", "message": message}to every subscriber. :rtype:NoneAdded in version 3.4.0.
- pending()[source]¶
Return the paths of the jobs queued or running, in submission order.
- Return type:
- submit(kind, path, policy, *, force=False)[source]¶
Queue a job unless the same
(kind, path)is already queued or running.With
force(a user’s “refresh now”) a duplicate is not dropped: a queued job is upgraded to run underpolicy, and a running one is followed by a second run underpolicy, so the refresh always starts after this call.- Parameters:
kind (
str) –"breakdown".path (
str) – escaped Drive path.policy (
RefreshPolicy) – the refresh policy the job runs under.force (
bool) – make sure a run underpolicystarts after this call, even when the path is already queued or running.
- Return type:
- Returns:
Trueif a job was queued (or upgraded, or a re-run queued),Falseif it was a duplicate (withoutforce) or the queue is closed.- Raises:
ValueError – for an unknown
kind.
Changed in version 3.4.0: Added
force.
- subscribe()[source]¶
Return a new queue that receives every event published from now on.
- Return type:
- tried(path)[source]¶
Return whether a breakdown job for
pathhas finished, either way, since start.- Return type:
- protonfs.webui.jobs.MAX_BACKLOG = 1000¶
Unread events a subscriber may have queued before it is dropped.