Skip to main content

A simple in-process python scheduler library with asyncio, threading and timezone support.Use datetime standard library objects for planning of Jobs depending on time cycles,fixed times, weekdays, dates, weights, offsets and execution counts.

Project description

scheduler

A simple in-process python scheduler library with asyncio, threading and timezone support. Schedule tasks by their time cycles, fixed times, weekdays, dates, weights, offsets and execution counts and automate Jobs.

repository mirror license pipeline status coverage report Documentation Status Code style: black

pkgversion versionsupport Downloads Week Downloads Total

Features

Installation

pip

scheduler can be installed directly from the PyPI repositories with:

pip install scheduler

Alternatively install scheduler from the git repository with:

git clone https://gitlab.com/DigonIO/scheduler.git
cd scheduler
pip install .

Arch Linux

The PKGBUILD file can be utilized from the Arch Build System. Download the PKGBUILD file and from within the containing folder run

makepkg -i

Example: How to schedule Jobs

The following example shows how the Scheduler is instantiated and how basic Jobs are created. For advanced scheduling examples please visit the online documentation.

import datetime as dt

from scheduler import Scheduler
import scheduler.trigger as trigger

def foo():
    print("foo")

schedule = Scheduler()

schedule.cyclic(dt.timedelta(minutes=10), foo)

schedule.minutely(dt.time(second=15), foo)
schedule.hourly(dt.time(minute=30, second=15), foo)
schedule.daily(dt.time(hour=16, minute=30), foo)
schedule.weekly(trigger.Monday(), foo)
schedule.weekly(trigger.Monday(dt.time(hour=16, minute=30)), foo)

schedule.once(dt.timedelta(minutes=10), foo)
schedule.once(trigger.Monday(), foo)
schedule.once(dt.datetime(year=2022, month=2, day=15, minute=45), foo)

A human readable overview of the scheduled jobs can be created with a simple print statement:

print(schedule)
max_exec=inf, tzinfo=None, priority_function=linear_priority_function, #jobs=9

type     function / alias due at                 due in      attempts weight
-------- ---------------- ------------------- --------- ------------- ------
MINUTELY bar(..)          2021-06-18 00:37:15   0:00:14         0/inf      1
CYCLIC   foo()            2021-06-18 00:46:58   0:09:58         0/inf      1
ONCE     foo()            2021-06-18 00:46:59   0:09:58           0/1      1
HOURLY   foo()            2021-06-18 01:30:15   0:53:14         0/inf      1
DAILY    bar(..)          2021-06-18 16:30:00  15:52:59         0/inf      1
WEEKLY   foo()            2021-06-21 00:00:00    2 days         0/inf      1
ONCE     bar(..)          2021-06-21 00:00:00    2 days           0/1      1
WEEKLY   bar(..)          2021-06-21 16:30:00    3 days         0/inf      1
ONCE     foo()            2022-02-15 00:45:00  242 days           0/1      1

Executing pending Jobs periodically can be achieved with a simple loop:

import time

while True:
    schedule.exec_jobs()
    time.sleep(1)

Documentation

The API documentation can either be viewed online or generated using Sphinx with numpydoc formatting. To build, run:

sphinx-build -b html doc/ doc/_build/html

Testing

Testing is done using pytest. With pytest-cov and coverage a report for the test coverage can be generated:

pytest --cov=scheduler/ tests/
coverage html

To test the examples in the documentation run:

pytest --doctest-modules doc/pages/*/*

License

This software is published under the LGPLv3 license.

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

scheduler-0.7.1.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

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

scheduler-0.7.1-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file scheduler-0.7.1.tar.gz.

File metadata

  • Download URL: scheduler-0.7.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for scheduler-0.7.1.tar.gz
Algorithm Hash digest
SHA256 0e63e644f4eeee9ab62861dadda28968a753efb409845c02f636a6a4546c70ed
MD5 5a171ceb2ab656ca2a6df49fa15057fe
BLAKE2b-256 27b0981d29cb765bd36c5c62797c6a3d5c8ccfba5629c462e2baa1be63acaa81

See more details on using hashes here.

File details

Details for the file scheduler-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: scheduler-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for scheduler-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7331a8fc8ee5d48befa836df8114724a47f2d443cbf7c95c6476935cb191ecf7
MD5 a07ddf28da6672b9f2d4ef43518395c4
BLAKE2b-256 44921929198592c2eeb97c85b08c995f8336209bd9e000d8fabb8ff67c669b51

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