Skip to main content

pypi docs codecov tests mypy code style: black

python

kaiju-scheduler is a simple asynchronous tasks scheduler / executor for asyncio functions. It adds a bit of extra such as retries, timeouts, execution policies etc.

Installation

With pip and python 3.8+:

pip3 install kaiju-scheduler

How to use

See the user guide for more info.

Initialize a scheduler and schedule your procedure for periodic execution. Then start the scheduler.

from kaiju_scheduler import Scheduler

async def call_async_procedure(*args, **kws):
    ...

async def main():
    scheduler = Scheduler()
    scheduler.schedule_task(call_async_procedure, interval_s=10, args=(1, 2), kws={'value': True})
    await scheduler.start()
    ...
    await scheduler.stop()

Alternatively you can use the scheduler contextually.

async def main():
    async with Scheduler() as scheduler:
        scheduler.schedule_task(call_async_procedure, interval_s=10, args=(1, 2), kws={'value': True})

Scheduler.schedule_task returns a task object which you can enable / disable or supress the task execution in your code temporarily using task.suspend context. You can also access the previous call results from task.result attribute.

class Cache:

    def __init__(self, scheduler: Scheduler):
        self._scheduler = scheduler
        self._cache_task = self._scheduler.schedule_task(
            self.cache_all, interval_s=600, policy=scheduler.ExecPolicy.WAIT)

    async def cache_all(self):
        ...

    async def reconfigure_cache(self):
        async with self._cache_task.suspend():
            "Do something while the caching is suspended"

You can specify retries for common types of errors such as IOError or ConnectionError using retries parameter. The scheduler will try to retry the call on such type of error.

scheduler.schedule_task(call_async_procedure, interval_s=300, retries=3, retry_interval_s=1)

There are various policies considering task execution. See the reference for more info on that.

Server

There's also a simple 'server' for handling asyncio tasks inside Python. It extends the standard loop functionality with retries, timeouts and impose some rate limit and prevent the loop from growing infinitely.

The server returns an asyncio.Task object which can be awaited independently. The idea is that any error is not raised but instead returned inside of the result. This allows for more convenient handling of errors while using this in streams, queues and server applications.

See the reference for more info on server functions.

from kaiju_scheduler import Server


async def call_something(arg1: int, arg2: int):
    return arg1 + arg2


async def main():
    async with Server() as server:
        task = await server.call(call_something, [1, 2])
        await task

Metadata

Release files for kaiju-scheduler 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for kaiju-scheduler 0.1.4
File Interpreter ABI Platform Actions
kaiju_scheduler-0.1.4-py3-none-any.whl Python 3 none any Details for kaiju_scheduler-0.1.4-py3-none-any.whl

Release files / kaiju_scheduler-0.1.4-py3-none-any.whl

Download URL kaiju_scheduler-0.1.4-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2047818f025be5e46976b99cf16c0e7eb61c3ddf23d2a938da493b2c24dc095
BLAKE2b-256 checksum
How to use checksums
2cc60b72532a35bf34ff394c0e6fe7674d78b8eca8ae6a01a33a7241b139b4a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Security for kaiju-scheduler 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page