upsies.jobs.custom

Custom job that provide the result of a coroutine

Classes

class upsies.jobs.custom.CustomJob(*, home_directory=None, cache_directory=None, cache_id='', ignore_cache=False, no_output_is_ok=False, hidden=False, autostart=True, guaranteed=False, precondition=None, prejobs=(), callbacks={}, **kwargs)[source]

Bases: JobBase

Wrapper around coroutine function

This job adds the following signals to signal:

indicate_activity

Emitted by indicate_activity(). Registered callbacks get the indicate_activity and text arguments as positional arguments.

property name

Internal name (e.g. for the cache file name)

property label

User-facing name

initialize(*, name, label, worker, catch=())[source]

Set internal state

Parameters:
  • name – Name for internal use

  • label – Name for user-facing use

  • worker

    Coroutine function that takes the job instance as a positional argument and returns this job’s output

    If worker returns any iterable that isn’t a string, each item is passed to add_output.

    If worker returns None, it is interpreted as “no output” and the job fails. An empty string is valid output and does not mean the job failed.

  • catch – Sequence of Exception classes to catch from worker and pass to error()

This job finishes when worker returns.

CancelledError from worker is ignored. Any other exceptions are passed to exception().

indicate_activity(indicate_activity=None, *, text=None)[source]

Emit the indicate_activity signal

Parameters:
  • indicate_activityTrue, False or None (i.e. do not change the current state)

  • textstr or None (i.e. do not change the current state)

async run()[source]

Do the work

This method is called by start(). Its coroutine is passed to add_task().

Any keyword arguments passed to initialize() are available via kwargs.

The job is_finished when all added tasks are done or cancelled. (See also finalize() and finalization().)

This method may call add_task() if more tasks are required.