In memory task schedule support cron tasks, interval tasks and onetime tasks. Using python's asyncio.
Project description
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.
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
taskbeat-0.1.0.tar.gz
(5.6 kB
view details)
Built Distribution
File details
Details for the file taskbeat-0.1.0.tar.gz
.
File metadata
- Download URL: taskbeat-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 066c0b0fdb2cd7150b7f5de9bffd9a516bb3178867dfee0bcd33d5d5a020068f |
|
MD5 | 3b5305e818df97531ba0fc405a9e29d9 |
|
BLAKE2b-256 | be9f8f8110d89891f45409087f641e2817335f72a25436544fa12f47bf824066 |
File details
Details for the file taskbeat-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: taskbeat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a391b02907d1f274401bc5e157a2522bfda546d67ae701ad80b1c95879c4447 |
|
MD5 | 74ea52be0fa0dd74d29486fa692f1085 |
|
BLAKE2b-256 | e96f95b80c737ed7c9745b631cd2fe2c1f8865b9abb164d9efd92f071772ba1a |