Skip to content

Repository files navigation

rescheduler

Build statusLicenseSupported Python versions

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:

importasyncioimportaioredisfromreschedulerimportScheduler, Jobdeftick():
print("tick")
deftack():
print("tack")
asyncdefcallback(job: Job):
ifjob.data['method'] =='tick':
tick()
elifjob.data['method'] =='tack':
tack()
asyncdefmain():
conn_pool=awaitaioredis.create_redis_pool(('localhost', 6379))
asyncwithScheduler(conn_pool=conn_pool, job_callback=callback, use_keyspace_notifications=True):
awaitasyncio.sleep(30)
conn_pool.close()
awaitconn_pool.wait_closed()
if__name__=='__main__':
asyncio.run(main())

Client side:

importasyncioimportaioredisfromreschedulerimportScheduler, Job, CronTriggerasyncdefmain():
conn_pool=awaitaioredis.create_redis_pool(('localhost', 6379))
scheduler=Scheduler(conn_pool=conn_pool, job_callback=lambda: None)
awaitscheduler.add_job(
Job(
id='tick-task',
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True),
data={'method': 'tick'},
)
)
awaitscheduler.add_job(
Job(
id='tack-task',
trigger=CronTrigger.parse(expr='*/10 * * * * *', seconds_ext=True),
data={'method': 'tack'},
),
delay=5.0,
)
conn_pool.close()
awaitconn_pool.wait_closed()
if__name__=='__main__':
asyncio.run(main())

About

python redis scheduler

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages