running functions on a schedule for Sanic
Project description
Sanic Scheduler
Sanic Scheduler runs a functions on a schedule.
Installation
Automatic installation:
$ pip install sanic-scheduler
Sanic Scheduler 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
Sanic Scheduler 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 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.6.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file sanic-scheduler-1.0.6.tar.gz
.
File metadata
- Download URL: sanic-scheduler-1.0.6.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3bd6b632fe72add9ad31eaf5707e9463808a7564405771c300f3bf331f3e808 |
|
MD5 | 1f9f4a33ea30b3b701f621d42b2ad95b |
|
BLAKE2b-256 | 1ab8ec1fadbde50f6c902e1d0169ca5b58210d818aecce9e0a94ea67d9294a40 |
File details
Details for the file sanic_scheduler-1.0.6-py3-none-any.whl
.
File metadata
- Download URL: sanic_scheduler-1.0.6-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b6b05c737745d5f8c56a549ee9ec42d5c6de91bf4b0b460bb4a0b59e61e0896 |
|
MD5 | d8ec03ca414b8444a327cca1a4cefdba |
|
BLAKE2b-256 | 708cb93d3d942ba89df6bf818b7194a65bd97a9615de499768e35db8d3a09f26 |