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)
Built Distribution
File details
Details for the file sanic-scheduler-1.0.5.tar.gz
.
File metadata
- Download URL: sanic-scheduler-1.0.5.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb6b3831825a62c2b9d55434e965c17c50b1cb5661fe1b721b09be1c3381829b |
|
MD5 | 83881a8ca8c5eb691dde0dd911954790 |
|
BLAKE2b-256 | 61fcc765c41e720ae605d2541e4602ba069a1296b2340e05cb82b8bd1829ce4f |
File details
Details for the file sanic_scheduler-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: sanic_scheduler-1.0.5-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 232b593dca8491204737afe76be7ef29484bc151e891d074824aa5e0cd0051d6 |
|
MD5 | adea7d68c82fcd4608545bd68a1b9bdf |
|
BLAKE2b-256 | 58eb01a7cc20a0b158cc138a5db6ed635e7f554049d14980be5cb87ada07c863 |