Spooler

my_spooler = Spooler.get_by_basename('myspooler')

# @Spooler.task() to  run on first available or to run on `my_spooler`:
@my_spooler.task(postpone=timedelta(seconds=1))
def run_me(a, b='c'):
    # We do:
    # * return True if task processed
    # * return None if task was ignored
    # * raise an exception to force task retry
    return True

# Now call this function as usual and it'll run in a spooler.
...
run_me('some', b='other')
...
uwsgiconf.runtime.spooler.spooler_task_types = {'fcall': <class 'uwsgiconf.runtime.spooler.SpoolerFunctionCallTask'>}

Known task types handlers will store here runtime.

SpoolerTask heirs are automatically registered in runtime by SpoolerTask.__init_subclass__.

class uwsgiconf.runtime.spooler.Spooler(name: str)

Gives an access to uWSGI Spooler related functions.

Warning

To use this helper one needs to configure spooler(s) in uWSGI config beforehand.

my_spooler = Spooler.get_by_basename('myspooler')

# @Spooler.task() to  run on first available or to run on `my_spooler`:
@my_spooler.task(postpone=timedelta(seconds=1))
def run_me(a, b='c'):
    ...

# Now call this function as usual and it'll run in a spooler.
...
run_me('some', b='other')
...
task(postpone=None)

Decorator. Used to register a function which should be run in Spooler.

my_spooler = Spooler.get_by_basename('myspooler')

# @Spooler.task() to  run on first available or to run on `my_spooler`:
@my_spooler.task(postpone=timedelta(seconds=1))  
def run_me(a, b='c'):
    ...
classmethod send_message_raw(message: str, *, spooler: Union[str, Spooler] = None, priority: int = None, postpone: Union[datetime.datetime, datetime.timedelta] = None, payload: Any = None) → str

Sends a message to a spooler.

Parameters:
  • message – Message to pass using spooler.
  • spooler – The spooler (id or directory) to use. Specify the ABSOLUTE path of the spooler that has to manage this task
  • priority

    Number. The priority of the message. Larger - less important.

    Warning

    This works only if you enable order_tasks option in spooler.set_basic_params().

  • postpone – Postpone message processing till.
  • payload – Object to pickle and pass within message.
classmethod get_spoolers() → List[uwsgiconf.runtime.spooler.Spooler]

Returns a list of registered spoolers.

classmethod get_by_basename(name: str) → Optional[uwsgiconf.runtime.spooler.Spooler]

Returns spooler object for a given directory name.

If there is more than one spooler with the same directory base name, the first one is returned.

If not found None is returned.

Parameters:name – Directory base name. E.g.: ‘mydir’ to get spooler for ‘/somewhere/here/is/mydir’
classmethod get_pids() → List[int]

Returns a list of all spooler processes IDs.

classmethod set_period(seconds: int) → bool

Sets how often the spooler runs.

Parameters:seconds
classmethod get_tasks() → List[str]

Returns a list of spooler jobs (filenames in spooler directory).

classmethod read_task_file(path: str) → dict

Returns a spooler task information.

Parameters:path – The relative or absolute path to the task to read.
class uwsgiconf.runtime.spooler.TaskResult(result: Any = None, *, exception: Exception = None)

Represents a task processing result.

class uwsgiconf.runtime.spooler.ResultProcessed(result: Any = None, *, exception: Exception = None)

Treat task as processed.

class uwsgiconf.runtime.spooler.ResultSkipped(result: Any = None, *, exception: Exception = None)

Treat task as skipped (ignored).

class uwsgiconf.runtime.spooler.ResultRescheduled(result: Any = None, *, exception: Exception = None)

Treat task as rescheduled (being due to retry).

class uwsgiconf.runtime.spooler.SpoolerTask(name: str, message: str, payload: Any)

Consolidates information for a spooler task.

mark_processed

alias of ResultProcessed

mark_skipped

alias of ResultSkipped

mark_rescheduled

alias of ResultRescheduled

process() → Union[uwsgiconf.runtime.spooler.TaskResult, bool, None]

Processes the task.

Supported results:
  • None - mark as ignored (skipped)
  • TaskResult - result type logic
  • exception - mark to retry
  • other - mark as processed
class uwsgiconf.runtime.spooler.SpoolerFunctionCallTask(name: str, message: str, payload: Any)

Function call type. Allows delegating function calls to spoolers.

process() → Union[uwsgiconf.runtime.spooler.TaskResult, bool, None]

Processes the task.

Supported results:
  • None - mark as ignored (skipped)
  • TaskResult - result type logic
  • exception - mark to retry
  • other - mark as processed