API reference

sisy.models.task_with_callable(the_callable, label=None, schedule=sisy.DEFAULT_SCHEDULE, userdata=None, pk_override=None)[source]
Parameters:
  • the_callable (object or str) – The function to call; can be object or string with dotted path.
  • label (str) – The string label for the task object. If not specified, will be set to the dotted path of the callable.
  • schedule (str) – The cron-formatted string specifying the execution schedule for the task. If not specified, will be set to the default schedule as defined in the Django setting SISY_DEFAULT_SCHEDULE, or, if that is not set, to ‘* * * * *’, which will execute once per minute.
  • userdata (dict) – A Python dictionary of JSON-serializable data. If not specified, the dictionary will be empty.
  • pk_override (int) – For use only when creating tasks by dotted path to Django model instance methods; provides instance primary key to enable retrieval of the model object in the remote worker.
Returns:

the Task object for the specified function. Must be saved before it will become active.

Return type:

sisy.models.Task

class sisy.models.Task[source]

Public fields

These fields are safe to modify directly in the task object, though it is usually easier to use the class methods to set them on task creation.

Variables:
  • label (str) – Name of the task, by default the same as the dotted Python path to the callable function
  • schedule (str) – Cron-format schedule for running the task
  • enabled (bool) – The task will not be scheduled if this field is false
  • start_running (datetime) – Datetime when the task is first eligible to run
  • end_running (datetime) – Datetime when the task is no longer eligible to run
  • wait_for_schedule (bool) – Should the task wait for its first scheduled run, or run immediately
  • iterations (int) – Number of iterations to schedule the task (0 means infinite)
  • allow_overlap (bool) – If false, sisy will not start a second worker on this task while one is already running

Internal fields

These fields are managed by code in the class methods; it is best to not modify them directly.

Variables:
  • created_at (datetime) – Datetime when the task was created
  • modified_at (datetime) – Datetime of the last modification of the task
  • last_run (datetime) – Datetime of latest task run (default is sisy.models.HAS_NOT_RUN)
  • next_run (datetime) – Calculated datetime of next scheduled task run
  • _func_info (str) – Internal dictionary of details about the callable function, stored as JSON
  • _extra_data (str) – Internal dictionary of userdata, stored as JSON. Access through the userdata property.
  • running (bool) – Internal flag to keep track of whether a worker is currently running this task, to avoid overlap if that has been specified
classmethod run_iterations(cls, the_callable, iterations=1, label=None, schedule='* * * * * *', userdata=dict, run_immediately=False, delay_until=None)[source]
Parameters:
  • the_callable (object or str) – The function to call; can be object or string with dotted path.
  • iterations (int) – The number of iterations that this task should run (according to its cron schedule)
  • label (str) – The string label for the task object. If not specified, will be set to the dotted path of the callable.
  • schedule (str) – The cron-formatted string specifying the execution schedule for the task. If not specified, will be set to ‘* * * * * *’, which will execute the iterations as fast as the SISY_HEARTBEAT_FREQUENCY setting allows (by default, once per minute).
  • userdata (dict) – A Python dictionary of JSON-serializable data. If not specified, the dictionary will be empty.
  • run_immediately (bool) – An optional flag which, if set to True, will cause the first iteration of the task to run immediately, instead of waiting for the cron schedule to indicate execution time.
  • delay_until (datetime) – If specified, the task will be delayed until the specified datetime by setting the Task object’s start_running field.
classmethod run_once(cls, the_callable, userdata=dict, delay_until=None)[source]
Parameters:
  • the_callable (object or str) – The function to call; can be object or string with dotted path.
  • userdata (dict) – A Python dictionary of JSON-serializable data. If not specified, the dictionary will be empty.
  • delay_until (datetime) – If specified, the task will be delayed until the specified datetime by setting the Task object’s start_running field.