Schedule Manager API Guide

This part of documentation provides all the interfaces of Schedule Manager. Detailed information about a specific function, class or method can be found here.

ScheduleManager Object

class schedule_manager.ScheduleManager[source]

Task schedule manager.

count

Number of tasks registered in the schedule manager.

Type:int
all_tasks

Get all tasks.

Type:TaskGroup
running_tasks

Get all running tasks.

Type:TaskGroup
pending_tasks

Get all pending tasks.

Type:TaskGroup
task(name)[source]

Get task registerd in schedule manager by name.

Parameters:name (str) – Task name.
Returns:Task instance.
Return type:Task
Raises:TaskNotFoundError – Task is not registered in schedule manager.
tasks(tag)[source]

Get tasks registerd in schedule manager by name.

Parameters:tag (Union[obj, list]) – Tag or tag list.
Returns:TaskGroup instance.
Return type:TaskGroup
register(task)[source]

Register a task.

Parameters:task (Task) – Task.
Returns:Registered task instance.
Return type:Task
Raises:TaskNameDuplicateError – Duplicate task name.
register_task(job, name=None, args=(), kwargs=None, ignore_skipped=True, daemon=True)[source]

Create and register a task.

Parameters:
  • job (callable) – Job to be scheduled.
  • name (str) – Task name. By default, a unique name is constructed.
  • args (tuple) – Argument tuple for the job invocation. Defaults to ().
  • kwargs (dict) – Dictionary of keyword arguments for the job invocation. Defaults to {}.
  • ignore_skipped (bool) – Set True to ignore skipped job if time spent on job is longer than the task cycle time. Defaults to True.
  • daemon (bool) – Set True to use as a daemon task. Defaults to True.
Returns:

Registered task instance.

Return type:

Task

Raises:

TaskNameDuplicateError – Duplicate task name.

unregister(name=None, tag=None)[source]

Unregister the task.

Parameters:
  • name (str) – Unregister task by name.
  • tag (Union[obj, list]) – Unregister tasks by tag or by a list of tags.

Task Object

class schedule_manager.Task(job, name=None, args=(), kwargs=None, ignore_skipped=True, daemon=True)[source]

Thread-based Task.

Task will be considered as periodic task by default.

Task is able to registered in ScheduleManager or run directly.

Parameters:
  • job (callable) – Job to be scheduled as a task.
  • name (str) – Task name. By default, a unique name is constructed.
  • args (tuple) – Argument tuple for the job invocation. Defaults to ().
  • kwargs (dict) – Dictionary of keyword arguments for the job invocation. Defaults to {}.
  • ignore_skipped (bool) – Set True to ignore skipped job if time spent on job is longer than the task cycle time. Defaults to True.
  • daemon (bool) – Set True to use as a daemon task. Defaults to True.
name

Task name.

Type:str
daemon

A boolean value indicating whether this task is based on a daemon thread.

See for threading.Thread.daemon more detail.

Type:bool
next_run

Datetime when the job run at next time.

Type:datetime
is_running

Return True if the task is running.

Type:bool
manager

Schedule manager which manages current task.

Type:ScheduleManager
tag

Tag list of the task.

Type:list
add_tag(tag)[source]

Add tag to task.

Parameters:tag (obj) – Tag.
Returns:Invoked task instance.
Return type:Task
add_tags(tags)[source]

Add a list of tags to task.

Parameters:tags (iterable) – Tag list.
Returns:Invoked task instance.
Return type:Task
remove_tag(tag)[source]

Remove tag from task.

Parameters:tag (obj) – Tag.
Returns:Invoked task instance.
Return type:Task
remove_tags(tags)[source]

Remove a list of tags from task.

Parameters:tags (iterable) – Tag list.
Returns:Invoked task instance.
Return type:Task
set_tags(tags)[source]

Set tag list to task.

Replace old tag list.

Parameters:tags (iterable) – Tag list.
Returns:Invoked task instance.
Return type:Task
delay(interval=None)[source]

Delay task start time.

Parameters:interval (Union[str, timedelta, int]) – Time interval. A string with format HH:MM:SS or timedelta or int in seconds. Or set None to cancel task delay time. Defaults to None.
Returns:Invoked task instance.
Return type:Task
Raises:TimeFormatError – Invalid time format.
start_at(at_time=None)[source]

Set task start time.

Specify a particular time that the job should be start.

Parameters:at_time (Union[str, datetime]) – Start time. A string or datetime. A string can be in one of the following formats: [HH:MM:SS, mm-dd HH:MM:SS]. Or set None to cancel task start time. Defaults to None.
Returns:Invoked task instance.
Return type:Task
Raises:TimeFormatError – Invalid time format.
nonperiodic(count)[source]

See as an non-periodic task.

Parameters:count (int) – Do the job for a certain number of times.
Returns:Invoked task instance.
Return type:Task
periodic()[source]

See as an periodic task.

Returns:Invoked task instance.
Return type:Task
period(interval)[source]

Scheduling periodic task.

Parameters:interval (Union[str, timedelta, int]) – Time interval. A string with format HH:MM:SS or timedelta or int in seconds.
Returns:Invoked task instance.
Return type:Task
Raises:TimeFormatError – Invalid time format.
period_at(unit='day', at_time='00:00:00', week_day='Monday', day=1)[source]

Scheduling periodic task.

Specify a particular time that the job should be run at.

Parameters:
  • unit (str) – Time unit of the periodic task. Defaults to day. The following unit is available: 1. day: Run job everyday. 2. week: Run job every week. 3. month: Run job every month.
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • week_day (str) – Week to do the job. Defaults to Monday. This argument will only be used is unit is week. A string should be one of following value: [“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”]
  • day (int) – Day to do the job. Defaults to 1. This argument will only be used is unit is month. Value should be in 1 ~ 31. Job will be skipped if specific date is not available.
Returns:

Invoked task instance.

Return type:

Task

Raises:

TimeFormatError – Invalid time format.

period_day_at(at_time='00:00:00')[source]

Scheduling periodic task.

Specify a particular time that the job should be run at. Job runs everyday.

Parameters:
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • week_day (str) – Week to do the job.
Returns:

Invoked task instance.

Return type:

Task

Raises:

TimeFormatError – Invalid time format.

period_week_at(at_time='00:00:00', week_day='Monday')[source]

Scheduling periodic task.

Specify a particular time that the job should be run at. Job runs every week.

Parameters:
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • week_day (str) – Week to do the job. Defaults to Monday. A string should be one of following value: [“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”]
Returns:

Invoked task instance.

Return type:

Task

Raises:

TimeFormatError – Invalid time format.

period_month_at(at_time='00:00:00', day=1)[source]

Scheduling periodic task.

Specify a particular time that the job should be run at. Job runs every month.

Parameters:
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • day (int) – Day to do the job. Defaults to 1. Value should be in 1 ~ 31. Job will be skipped if specific date is not available.
Returns:

Invoked task instance.

Return type:

Task

Raises:

TimeFormatError – Invalid time format.

start()[source]

Start the Task’s activity.

stop()[source]

Stop the Task’s activity.

pause()[source]

Pause the Task’s activity.

Works only the task is registered into ScheduleManager.

TaskGroup Object

class schedule_manager.TaskGroup(tasks=None)[source]

Task group.

A set of tasks.

count

Number of tasks contained in the group.

Type:int
set_manager(manager=None)[source]

Change schedule manager of all tasks.

Task will be unregistered from old manager if it has been registered in a manager.

Parameters:manager (ScheduleManager) – A exist schedule manager object. Set None to create new schedule manager.
Returns:Invoked ScheduleManager instance.
Return type:ScheduleManager
Raises:TaskNameDuplicateError – There is a duplicate task name.
add_tag(tag)[source]

Add tag to tasks.

Parameters:tag (obj) – Tag.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
add_tags(tags)[source]

Add a list of tags to tasks.

Parameters:tags (iterable) – Tag list.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
remove_tag(tag)[source]

Remove tag from tasks.

Parameters:tag (obj) – Tag.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
remove_tags(tags)[source]

Remove a list of tags from tasks.

Parameters:tags (iterable) – Tag list.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
set_tags(tags)[source]

Set tag list to tasks.

Replace old tag list.

Parameters:tags (iterable) – Tag list.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
delay(interval=None)[source]

Delay task start time.

Parameters:interval (Union[str, timedelta, int]) – Time interval. A string with format HH:MM:SS or timedelta or int in seconds. Or set None to cancel task delay time. Defaults to None.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
Raises:TimeFormatError – Invalid time format.
start_at(at_time)[source]

Set task start time.

Specify a particular time that the job should be start.

Parameters:at_time (Union[str, datetime]) – Start time. A string or datetime. A string can be in one of the following formats: [HH:MM:SS, mm-dd HH:MM:SS]. Or set None to cancel task start time. Defaults to None.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
Raises:TimeFormatError – Invalid time format.
nonperiodic(count)[source]

See as non-periodic tasks.

Parameters:count (int) – Do the job for a certain number of times.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
periodic()[source]

See as periodic tasks.

Returns:Invoked TaskGroup instance.
Return type:TaskGroup
period(interval)[source]

Scheduling periodic tasks.

Parameters:interval (Union[str, timedelta, int]) – Time interval. A string with format HH:MM:SS or timedelta or int in seconds.
Returns:Invoked TaskGroup instance.
Return type:TaskGroup
Raises:TimeFormatError – Invalid time format.
period_at(unit='day', at_time='00:00:00', week_day='Monday', day=1)[source]

Scheduling periodic tasks.

Specify a particular time that the job should be run at.

Parameters:
  • unit (str) – Time unit of the periodic task. Defaults to day. The following unit is available: 1. day: Run job everyday. 2. week: Run job every week. 3. month: Run job every month.
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • week_day (str) – Week to do the job. Defaults to Monday. This argument will only be used is unit is week. A string should be one of following value: [“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”]
  • day (int) – Day to do the job. Defaults to 1. This argument will only be used is unit is month. Value should be in 1 ~ 31. Job will be skipped if specific date is not available.
Returns:

Invoked TaskGroup instance.

Return type:

TaskGroup

Raises:

TimeFormatError – Invalid time format.

period_day_at(at_time='00:00:00')[source]

Scheduling periodic tasks.

Specify a particular time that the job should be run at. Job runs everyday.

Parameters:
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • week_day (str) – Week to do the job.
Returns:

Invoked TaskGroup instance.

Return type:

TaskGroup

Raises:

TimeFormatError – Invalid time format.

period_week_at(at_time='00:00:00', week_day='Monday')[source]

Scheduling periodic tasks.

Specify a particular time that the job should be run at. Job runs every week.

Parameters:
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • week_day (str) – Week to do the job. Defaults to Monday. A string should be one of following value: [“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”]
Returns:

Invoked TaskGroup instance.

Return type:

TaskGroup

Raises:

TimeFormatError – Invalid time format.

period_month_at(at_time='00:00:00', day=1)[source]

Scheduling periodic tasks.

Specify a particular time that the job should be run at. Job runs every month.

Parameters:
  • at_time (str) – Time to do the job. A string with format HH:MM:SS. Defaults to 00:00:00.
  • day (int) – Day to do the job. Defaults to 1. Value should be in 1 ~ 31. Job will be skipped if specific date is not available.
Returns:

Invoked TaskGroup instance.

Return type:

TaskGroup

Raises:

TimeFormatError – Invalid time format.

start()[source]

Start the Tasks’ activity.

stop()[source]

Stop the Tasks’ activity.

pause()[source]

Pause the Tasks’ activity.

Works only the task is registered into ScheduleManager.

Exceptions

class schedule_manager.exceptions.OperationFailError[source]

Operation fail exception.

class schedule_manager.exceptions.TaskNameDuplicateError[source]

Duplicate task name exception.

class schedule_manager.exceptions.TaskNotFoundError[source]

Task is not registered in schedule manager.

class schedule_manager.exceptions.TimeFormatError[source]

Time format error.