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 timedelta, time
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))
@task(timedelta(hours=1), time(hour=1, minute=30))
async def foo_bar(_):
"""Runs the function every 1 hours after 1:30."""
print("Foo")
await asyncio.sleep(1)
print("Bar")
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.3.tar.gz
(3.1 kB
view hashes)
Built Distributions
Close
Hashes for sanic_scheduler-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f0c0cb1ebdcba8cd4dd354fb1c60537636d00577d75aec1d7c0ed242fecb9f2 |
|
MD5 | a8531b26a951baa93ecf4add54bcb53f |
|
BLAKE2b-256 | a0312bdd280c198ff073bcd340d5fefc099146217850a8fe15d11e2272f839a2 |
Close
Hashes for sanic_scheduler-1.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9e6a288e7f108fcf566786ab5df2362eb7beb3f68151c87957653988f5cc590 |
|
MD5 | 66b82819efc6a808db73c6a505e29423 |
|
BLAKE2b-256 | 92ea8ecaa8d15e7f80f4bf1786b6430a701c48aa215c20b199c3e58b6020fc05 |