Skip to main content

Schedule your tasks, easily

Project description

Taskeduler: schedule your tasks, easily

This module is a tool written in python built to automate tasks.

Write a python function and configure the task in a yaml file. Then it is going to be executed following the programed scheduler.

How to schedule a task

There are two main ways to use the Taskeduler: describing the tasks in a yaml file and running the module passing the file as an argument, or embeding the module in another python project, importing the TaskManager and adding the tasks manually.

There are examples of both usages in the example file.

Via YAML file

There are 3 main elements that are reperented in the yaml file: the task name, the task entrypoint and the task schedule.

my_task:
  # Here goes the entrypoint information.
  script:
    # The path to the file where the entrypoint function is defined.
    file: ${SCRIPTS_DIR}/here/lies/the/entrypoint.py
    # The proper name of the entrypoint function.
    entrypoint: my_entrypoint_function
    # The entrypoint args and kwargs if wanted.
    args:
        - first_argument
        - ...
    kwargs:
        kwarg_name: kwarg_value
        ...
  # Here goes the schedule information.
  repeat:
    # How often the task will be repeated.
    frequency: ['daily']
    # Some additional rules about when will the task be executed.
    execution_rules:
      week_day: ["mon", "tue", "wed", "thu", "fri"]
      time: ["10:00"]

You may note that the parsing of the YAML file will resolve environment variables if enclosed into braces, preceded with the dollar sign: ${ENV_VARIABLE}.

All the fields shown above are mandatory except of All the fields shown in the previous example are mandatory except args, kwargs and the proper execution rules. To read more about the execution rules, go to the scheduler rules section.

The frecuency and all the execution rules are ment to be iterables in the YAML definition, there will be created a task for each defined frecuency, named as task_name_frequency.

Via Python code

To build the Task object, first is needed to create a Scheduler. Then, to execute the task is required to add the task to a TaskManager, and run the loop.

>>> from taskeduler.scheduler import ExecutionRulesManager, Scheduler
>>> from taskeduler.task import Task, TaskManager
>>>
>>> # Define the entrypoint function
>>> def my_entrypoint_function(name: str) -> None:
...     print(f"Hello {name}! What's up?")
>>>
>>> # Create the Scheduler and the ExecutionRulesManager
>>> scheduler = Scheduler(
...     frecuency="daily",
...     execution_rules_manager=ExecutionRulesManager(
...         week_days=["mon", "tue", "wed", "thu", "fri"],
...         time=["10:00"]
...     )
... )
>>>
>>> # Create the task
>>> task = Task(
...     scheduler=scheduler,
...     task=greet,
...     args=("Peter",)
... )
>>>
>>> # Setup the TaskManager and run the loop
>>> task_manager = TaskManager()
>>> task_manager.add_task("test_taskeduler", task)
>>> task_manager.loop.start()

You can also load a YAML from the python code!

>>> from taskeduler import schedule
>>> my_yaml = "/path/to/my/file.yaml"
>>> task_manager = schedule(yaml_file=my_yaml)
>>> task_manager.loop.start()

Even with an already existing task_manager:

>>> from taskeduler import TaskManager, schedule
>>> task_manager = TaskManager()
>>> my_yaml = "/path/to/my/file.yaml"
>>> schedule(yaml_file=my_yaml, task_manager=task_manager)
>>> task_manager.loop.start()

Scheduler rules

The frequencies determine the period of wait between the task executions. The execution rules determine some aditional "checks" that must be met, represented by a list of possible values.

There are 6 scheduler frequencies and 4 execution rules available:

  • Scheduler Frecuencies:
    • minutely: Repeat every minute. i.e: 10:10 => 10:11
    • hourly: Repeat every hour. i.e: 10:10 => 11:10
    • daily: Repeat every day. i.e: 11 jul => 12 jul
    • weekly: Repeat every week (based on the week day). i.e: monday 1 => monday 8
    • monthly: Repeat every month (based on the month day). i.e: January 27 => February 27; January 29 => February 29 (leap year)// March 1
    • yearly: Repeat every year (based on the month day and month). i.e: 20 aug 2019 => 20 aug 2020
  • Execution Rules:
    • time: This restriction determines the hour and minute when the task can be executed in a HH:MM format.
    • month_days: This restriction determines the number of day in the month when the task can be executed.
    • week_days: This restriction determines the week day when the task can be executed, in any of the following formats:
      • full name: monday, tuesday, ...
      • short name: mon, tue, ...
      • number: 0, 1, ...
    • month: This restriction determines the month when the task can be executed, in any of the following formats:
      • full name: january, february, ...
      • short name: jan, feb, ...
      • number: 1, 2, ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

taskeduler-1.0.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

taskeduler-1.0.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file taskeduler-1.0.1.tar.gz.

File metadata

  • Download URL: taskeduler-1.0.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for taskeduler-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1d4ee6c21b9772070f5232e3e651d461d75bfbdff884ea9a2fe5a3b19c8977a4
MD5 b86a7c7d6a5ad79bee3cf59db0fb364a
BLAKE2b-256 f3d495e050fb3f08f4266777cb3e338bde9d066911dea9cf52da1d96d58b3ea4

See more details on using hashes here.

File details

Details for the file taskeduler-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: taskeduler-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for taskeduler-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42069046a37c941d9dfc6e77963b52b87ee386ec71f75ad3141e3a2662c008f0
MD5 edf7641bf5238776b7b5008433297a19
BLAKE2b-256 1adf893d99162b16e6c0e84867a297e7f1012cfd3048919e4ed99808e32b9a44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page