Skip to main content

taskbeat

In memory task schedule support cron tasks, interval tasks and onetime tasks. Using python's asyncio.

Install

pip install taskbeat

Important

More than 1,000,000 60-SECOND-CYCLE tasks may cuase task delay sometimes. The limit is depends on your CPU mostly, you'd better to test to find the limitation on you server before you use it in production.

Python Compatibility

  • Compatible with python3.7 and above.
  • Tested with python3.7, python3.8, python3.9, python3.10, python3.11 and python3.12.

Example 1

import time
import logging
import asyncio

from taskbeat import TaskBeat

_logger = logging.getLogger(__name__)


async def report(beat):
    """It should be showing report every second.

    If it is not showing report every second,
    then your tasks mostly are not fired on time.
    """
    last_counter = 0
    while True:
        delta = beat.event_counter - last_counter
        last_counter = beat.event_counter
        with open("stats.txt", "a", encoding="utf-8") as fobj:
            fobj.write(str(time.time()) + " " + str(delta) + "\n")
        await asyncio.sleep(1)


async def beat_server():
    beat = TaskBeat()
    task = asyncio.create_task(report(beat))
    for i in range(800 * 1000):
        event_id = "cron_{}".format(i)
        await beat.update_cron_task(event_id, "* * * * *")
    while True:
        event_id = await beat.get_event(5)
        if event_id == "cron_1":
            # should be showing every minute
            # see how many seconds a task may daley here
            _logger.info("cron_1=%s", time.time())


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    asyncio.run(beat_server())

Releases

v0.1.0

  • First release.

v0.1.1

  • Fix delete_task problem.

Release files for taskbeat 0.1.1

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

Source distribution (sdist)

Source distribution for taskbeat 0.1.1
File Size Uploaded
taskbeat-0.1.1.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for taskbeat 0.1.1
File Interpreter ABI Platform
taskbeat-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / taskbeat-0.1.1.tar.gz

Download URL taskbeat-0.1.1.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
304f20576b07bcf5793680356f3db5ed1094669980369883f08af6b1ef58c267
BLAKE2b-256 checksum
How to use checksums
1a04370c230ea292a493295936b640e3beb6a3f8f71dd250ea03e118fe6271cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / taskbeat-0.1.1-py3-none-any.whl

Download URL taskbeat-0.1.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c93be073b1a4afeaa199d92ae11d1fc23fb5f507c6b2f0a1f76492ae0f2c843
BLAKE2b-256 checksum
How to use checksums
7514647c1fffc70046f15d8e21c6d897a6ae971fcfa0ac153871be0afc3ddd61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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