running functions on a schedule for Sanic
Project description
# SanicScheduler
SanicScheduler runs a functions on a schedule.
## Installation
Automatic installation:
```bash
$ pip install sanic-scheduler
```
SanicScheduler is listed in [PyPI](https://pypi.python.org/pypi/sanic-scheduler) and can be installed with pip or easy_install.
Manual installation:
```bash
$ git clone https://github.com/asmodius/sanic-scheduler.git
$ cd sanic_scheduler
$ python setup.py install
```
SanicScheduler source code is [hosted on GitHub](https://github.com/asmodius/sanic-scheduler)
## Usage
```python
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)
```
SanicScheduler runs a functions on a schedule.
## Installation
Automatic installation:
```bash
$ pip install sanic-scheduler
```
SanicScheduler is listed in [PyPI](https://pypi.python.org/pypi/sanic-scheduler) and can be installed with pip or easy_install.
Manual installation:
```bash
$ git clone https://github.com/asmodius/sanic-scheduler.git
$ cd sanic_scheduler
$ python setup.py install
```
SanicScheduler source code is [hosted on GitHub](https://github.com/asmodius/sanic-scheduler)
## Usage
```python
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.1.tar.gz
(2.9 kB
view details)
File details
Details for the file sanic-scheduler-1.0.1.tar.gz
.
File metadata
- Download URL: sanic-scheduler-1.0.1.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7153f1ab281b87a18d1e2fcf07ed3b903ccc13900bbd8089c9c5cc2f5d1d212 |
|
MD5 | 6ce0a048ac2492ab8bf5118293672e7c |
|
BLAKE2b-256 | 69308a988465cbf8742d5b31debf20e551017b0912e3d99fc95c740b74f4f1ba |