Skip to main content

When you have to do something... later.

Project description

DoItLater

A simple python library to schedule work in the future with ability to loop infinitely. Does not depend on any 3rd party libraries.


Installation

The package can be simply installed using on of these methods:

  • pip: pip install doitlater
  • poetry: poetry add doitlater
  • poetry: poetry add git+https://github.com/evalkaz/doitlater.git

Usage

Simplest example:

from datetime import datetime, timedelta
from doitlater import Later

later = Later()

@later.on(datetime(2021, 1, 1))
def say_hello():
    print("Happy new years in 2021!")

if __name__ == "__main__":
    later.do()

To call the same function every 10 seconds with 30 seconds cold start:

@later.on(
    datetime.now() + timedelta(seconds=30),
    timedelta(seconds=10),
    loop=True
)
def repeatable_work():
    print("Hello every 10 seconds!")

The later.on() is stackable so this will work too (will be executed every 5 and every 7 days):

@later.on(datetime(2021, 1, 1), timedelta(days=5))
@later.on(datetime(2021, 1, 1), timedelta(weeks=1))
def say_hello():
    print("Happy new years in 2021!")

You can also pass a list of datetime or timedelta (or a mixed one) when to execute the function:

@later.on(datetime(2021, 1, 1), [
    datetime(2021, 2, 1),
    datetime(2021, 3, 1),
    timedelta(days=31)], loop=False)
def say_hello():
    print("Happy new years in 2021!")

If you want to stop executing the same function just return False:

@later.on(datetime(2021, 1, 1), timedelta(seconds=5), loop=True)
def only_one_hello():
    print("This will appear only once!")
    return False

If you have multiple functions and one of them throws an exception but you don't want to stop the work, pass ignore_errors=True to Later() object:

later = Later(ignore_errors=True)

By default, library will output logs on errors. To change logging, use dictConfig:

from datetime import datetime, timedelta
from doitlater import Later
from logging.config import dictConfig

dictConfig(
    {
        "version": 1,
        "formatters": {
            "default": {
                "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s",
            }
        },
        "handlers": {
            "default": {"class": "logging.StreamHandler", "formatter": "default",}
        },
        "root": {"level": "INFO", "handlers": ["default"]},
    }
)

later = Later()

@later.on(datetime(2021, 1, 1))
def say_hello():
    print("Happy new years in 2021!")

if __name__ == "__main__":
    later.do()

API

Later(workers, ignore_errors) takes these parameters:

  • workers - number of threads to use, defaults to maximum number of threads supported by CPU.
  • ignore_errors - False will exit when one of the function throws an error, True - ignores exceptions and will resume the work.

later.on(exactly, repeat, loop) function takes these parameters:

  • exactly - on which time perform the first function call.
  • repeat - a single value or a list of datetime, timedelta or both on when to repeat the call. If None is passed the function will not be called again. Defaults to None.
  • loop - whether repeat calling times from repeat. Defaults to True.

later.do() does not take any parameters.

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

DoItLater-0.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

DoItLater-0.1.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file DoItLater-0.1.2.tar.gz.

File metadata

  • Download URL: DoItLater-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.6.9 Linux/4.4.0-148-generic

File hashes

Hashes for DoItLater-0.1.2.tar.gz
Algorithm Hash digest
SHA256 92d4bb4c9c397d9baceeb441f676ca60bbf704a15f3130fa27d38d17ce5fec02
MD5 15415184f842e54707dcae6b125436ed
BLAKE2b-256 0d825415e9adeee36ea3be33158c0004a2e67e26eedf78f3de9b5a24c41df802

See more details on using hashes here.

File details

Details for the file DoItLater-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: DoItLater-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.6.9 Linux/4.4.0-148-generic

File hashes

Hashes for DoItLater-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4fbdf144a26164c3e3583e26916075acb46283a89382ba747c5b4844f7d522e1
MD5 f60fc20b6eeade6430fa20b2715ea317
BLAKE2b-256 8ad43e89222c17369c188638dbf2b941d951dbafb9184995fcde7dc69ceb07cc

See more details on using hashes here.

Supported by

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