Skip to main content

Python redis scheduler

Project description

Build status License Supported 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:

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


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 details)

Uploaded Source

File details

Details for the file rescheduler-0.1.0.tar.gz.

File metadata

  • Download URL: rescheduler-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for rescheduler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f11f9d4cf7dcbf12d6182fec7348681523943b3f4750193c23ab48820c3872e2
MD5 00dfba190fcd28ad56595ca7b277be1e
BLAKE2b-256 dfdf4a6035215a70dabe1402c260b192f8aa9e46391d8acd192d68d5489a8002

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page