Python redis scheduler
Project description
rescheduler is a task scheduler built on top of redis. It stores all jobs and schedules in redis which provides persistency (depends on redis persistent level configuration), distributed work (multiple schedulers allowed to be run simultaneously) and fault tolerance (in case of one scheduler crash the others takes away its jobs).
Installation
You can install rescheduler with pip:
$ pip install rescheduler
Quickstart
Server side:
import asyncio
import aioredis
from rescheduler import Scheduler, Job
def tick():
print("tick")
def tack():
print("tack")
async def callback(job: Job):
if job.data['method'] == 'tick':
tick()
elif job.data['method'] == 'tack':
tack()
async def main():
conn_pool = await aioredis.create_redis_pool(('localhost', 6379))
async with Scheduler(conn_pool=conn_pool, job_callback=callback, use_keyspace_notifications=True):
await asyncio.sleep(30)
conn_pool.close()
await conn_pool.wait_closed()
if __name__ == '__main__':
asyncio.run(main())
Client side:
import asyncio
import aioredis
from rescheduler import Scheduler, Job, CronTrigger
async def main():
conn_pool = await aioredis.create_redis_pool(('localhost', 6379))
scheduler = Scheduler(conn_pool=conn_pool, job_callback=lambda: None)
await scheduler.add_job(
Job(
id='tick-task',
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True),
data={'method': 'tick'},
)
)
await scheduler.add_job(
Job(
id='tack-task',
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True),
data={'method': 'tack'},
),
delay=5.0,
)
conn_pool.close()
await conn_pool.wait_closed()
if __name__ == '__main__':
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rescheduler-0.1.0.tar.gz
(8.7 kB
view hashes)