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: object

Runs breakdown jobs on worker threads and one walk on its own thread.

Events published to subscribers (each a dict with an "event" key):

  • breakdown: path and the finished breakdown (a Breakdown).

  • trash: trash, the engine’s trash summary or None (after a breakdown of /).

  • progress: done, total, path and state (running, done, cancelled or error), aggregated over every path of the walk. The last event of a walk is never running; a cancelled or error one keeps the last known done and total (error adds message). The last event also carries failed: how many folders could not be measured (their subtrees were not walked).

  • error: path and message for 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 current GuiSettings; 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; None for no logging. Called from any thread.

A subscriber whose queue holds MAX_BACKLOG unread events is dropped: its queue receives a final None after the backlog is discarded.

Added in version 3.4.0.

close()[source]

Stop the workers and end every subscriber’s stream (a None is queued to each).

Return type:

None

notify(message)[source]

Publish {"event": "notice", "message": message} to every subscriber. :rtype: None

Added in version 3.4.0.

pending()[source]

Return the paths of the jobs queued or running, in submission order.

Return type:

list

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 under policy, and a running one is followed by a second run under policy, 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 under policy starts after this call, even when the path is already queued or running.

Return type:

bool

Returns:

True if a job was queued (or upgraded, or a re-run queued), False if it was a duplicate (without force) 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:

Queue

tried(path)[source]

Return whether a breakdown job for path has finished, either way, since start.

Return type:

bool

unsubscribe(q)[source]

Stop sending events to q (a no-op if it is not subscribed).

Return type:

None

walk(paths, cancel)[source]

Start walking paths one after another on a new thread.

Parameters:
  • paths (list) – escaped Drive paths; each is walked with the current settings.

  • cancel (Event) – set it to stop before the next folder.

Return type:

bool

Returns:

False if a walk is already running (or the queue is closed).

protonfs.webui.jobs.MAX_BACKLOG = 1000

Unread events a subscriber may have queued before it is dropped.