Skip to main content

running functions on a schedule for Sanic

Project description

SanicScheduler

SanicScheduler runs a functions on a schedule.

Installation

Automatic installation:

$ pip install sanic-scheduler

SanicScheduler is listed in PyPI and can be installed with pip or easy_install.

Manual installation:

$ git clone https://github.com/asmodius/sanic-scheduler.git
$ cd sanic_scheduler
$ python setup.py install

SanicScheduler source code is hosted on GitHub

Usage

import asyncio
from datetime import datetime, time, timedelta

from sanic import Sanic

from sanic_scheduler import SanicScheduler, task


app = Sanic()
scheduler = SanicScheduler(app)


@task(timedelta(seconds=30))
def hello(app):
    """Runs the function every 30 seconds."""
    print("Hello, {0}".format(app), datetime.now())


@task(timedelta(hours=1), time(hour=1, minute=30))
async def foo_bar(_):
    """Runs the function every 1 hours after 1:30."""
    print("Foo", datetime.now())
    await asyncio.sleep(1)
    print("Bar")


@task(timedelta(minutes=2), timedelta(seconds=10))
def baz(_):
    """Runs the function every 2 minutes hours after 10 seconds."""
    print("Baz", datetime.now())


@task(start=timedelta(seconds=10))
def another(_):
    """Run the function after 10 seconds once."""
    print("another", datetime.now())


if __name__ == "__main__":
    app.run(host='127.0.0.1', port=5000, debug=True)

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

sanic-scheduler-1.0.5.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

sanic_scheduler-1.0.5-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file sanic-scheduler-1.0.5.tar.gz.

File metadata

File hashes

Hashes for sanic-scheduler-1.0.5.tar.gz
Algorithm Hash digest
SHA256 bb6b3831825a62c2b9d55434e965c17c50b1cb5661fe1b721b09be1c3381829b
MD5 83881a8ca8c5eb691dde0dd911954790
BLAKE2b-256 61fcc765c41e720ae605d2541e4602ba069a1296b2340e05cb82b8bd1829ce4f

See more details on using hashes here.

File details

Details for the file sanic_scheduler-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sanic_scheduler-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 232b593dca8491204737afe76be7ef29484bc151e891d074824aa5e0cd0051d6
MD5 adea7d68c82fcd4608545bd68a1b9bdf
BLAKE2b-256 58eb01a7cc20a0b158cc138a5db6ed635e7f554049d14980be5cb87ada07c863

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