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.4.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file sanic-scheduler-1.0.4.tar.gz
.
File metadata
- Download URL: sanic-scheduler-1.0.4.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35b4ac1ca09c38ee2618c8038b084167bff77df5e08c3f6167b52959faf5988f |
|
MD5 | 3de6f7d4308be24a89d2848a70db5ec9 |
|
BLAKE2b-256 | e4860a34190639841433b23c49a6da86d242010f67c12b0de4ea2a8a0551e8aa |
File details
Details for the file sanic_scheduler-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: sanic_scheduler-1.0.4-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91ef0fb5bb83d264ebeb30cb83ff6bcc95f4e518bdf67d994414c3f28b1a50d7 |
|
MD5 | 683570dd1de547d0672185b67df46a22 |
|
BLAKE2b-256 | e2ad1db30c5397f49f949fe3dd5a26b3072ad292755d8f2f75a4b3fac6d9ca9b |