upsies.jobs.jobrunner

Manage a bunch of jobs

Classes

class upsies.jobs.jobrunner.JobRunner(jobs=(), id='anonymous')[source]

Bases: Mapping

Wrapper around a bunch of JobBase subclasses to manage them collectively

This class subclasses Mapping for easy access to jobs. Keys are job names and values are the JobBase instances.

Parameters:
add(*jobs)[source]

Add jobs

Every job must have a unique name.

Parameters:

jobsJobBase subclasses

property all_jobs

All add()ed jobs as a flat sequence

property enabled_jobs

Same as all_jobs, but without any jobs that are not is_enabled

start_more_jobs()[source]

start() all jobs that are ready to start

Jobs that have autostart unset are not started.

Jobs may also not be started if they are disabled or otherwise unstartable. See start().

Note

This method must be called while an asyncio event loop is running because JobBase.start() calls JobBase.add_task(), and a task must be added to a loop to run.

async wait()[source]

Wait for all jobs that are started and not finished

Note

This does not raise exceptions from jobs. See exceptions after calling this method.

terminate(reason=None)[source]

Terminate all_jobs

property all_jobs_finished

Whether all enabled_jobs are finished

property exceptions

Sequence of Exception instances raised by any job