Tags#

The scheduler library provides a tagging system for Job categorization. This allows for collective selection and deletion of Jobs.

Create a number of tagged Jobs using the tags attribute. For demonstration we mix the tags spam, eggs, ham and sausage, where spam is a tag of every Job:

>>> import datetime as dt

>>> from scheduler import Scheduler

>>> def foo():
...     print("foo")
...

>>> schedule = Scheduler()

>>> dish1 = schedule.once(dt.timedelta(), foo, tags={"spam", "eggs"})
>>> dish2 = schedule.once(dt.timedelta(), foo, tags={"spam", "ham"})
>>> dish3 = schedule.once(dt.timedelta(), foo, tags={"spam", "ham", "eggs"})
>>> dish4 = schedule.once(dt.timedelta(), foo, tags={"spam", "sausage", "eggs"})

The default behaviour of Job selection by tags require a Job to contain all of the targeted tags for a match. If the any_tag flag is set to True, only one of the targeted tags has to exist in the Job for a match. Scheduler currently supports the tagging system for the functions

get_jobs() and delete_jobs().

Note

If an empty set of tags is be passed to above functions, no filter is applied and all Jobs are selected.

Match all tags#

This is the default behavior.

>>> dishes = schedule.get_jobs({"ham", "eggs"})
>>> dishes == {dish3}
True

>>> dishes = schedule.get_jobs({"eggs"})
>>> dishes == {dish1, dish3, dish4}
True

Match any tag#

With the any_tag flag set to True, one matching tag is sufficient:

>>> dishes = schedule.get_jobs({"sausage", "ham"}, any_tag=True)
>>> dishes == {dish2, dish3, dish4}
True

>>> dishes = schedule.get_jobs({"eggs"}, any_tag=True)
>>> dishes == {dish1, dish3, dish4}
True

Note

Additionally the tagging system is supported by the delete_jobs() method.