taskbeat


Nametaskbeat JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryIn memory task schedule support cron tasks, interval tasks and onetime tasks. Using python's asyncio.
upload_time2023-10-31 14:56:38
maintainerChen Jia
docs_urlNone
authorChen Jia
requires_python>=3.7
licenseMIT
keywords taskbeat
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "taskbeat",
    "maintainer": "Chen Jia",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "chenjia@zencore.cn",
    "keywords": "taskbeat",
    "author": "Chen Jia",
    "author_email": "chenjia@zencore.cn",
    "download_url": "https://files.pythonhosted.org/packages/1a/04/370c230ea292a493295936b640e3beb6a3f8f71dd250ea03e118fe6271cf/taskbeat-0.1.1.tar.gz",
    "platform": null,
    "description": "# taskbeat\n\nIn memory task schedule support cron tasks, interval tasks and onetime tasks. Using python's asyncio.\n\n## Install\n\n```\npip install taskbeat\n```\n\n## Important\n\nMore 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.\n\n## Python Compatibility\n\n- Compatible with python3.7 and above.\n- Tested with python3.7, python3.8, python3.9, python3.10, python3.11 and python3.12.\n\n## Example 1\n\n```python\nimport time\nimport logging\nimport asyncio\n\nfrom taskbeat import TaskBeat\n\n_logger = logging.getLogger(__name__)\n\n\nasync def report(beat):\n    \"\"\"It should be showing report every second.\n\n    If it is not showing report every second,\n    then your tasks mostly are not fired on time.\n    \"\"\"\n    last_counter = 0\n    while True:\n        delta = beat.event_counter - last_counter\n        last_counter = beat.event_counter\n        with open(\"stats.txt\", \"a\", encoding=\"utf-8\") as fobj:\n            fobj.write(str(time.time()) + \" \" + str(delta) + \"\\n\")\n        await asyncio.sleep(1)\n\n\nasync def beat_server():\n    beat = TaskBeat()\n    task = asyncio.create_task(report(beat))\n    for i in range(800 * 1000):\n        event_id = \"cron_{}\".format(i)\n        await beat.update_cron_task(event_id, \"* * * * *\")\n    while True:\n        event_id = await beat.get_event(5)\n        if event_id == \"cron_1\":\n            # should be showing every minute\n            # see how many seconds a task may daley here\n            _logger.info(\"cron_1=%s\", time.time())\n\n\nif __name__ == \"__main__\":\n    logging.basicConfig(level=logging.INFO)\n    asyncio.run(beat_server())\n```\n\n## Releases\n\n### v0.1.0\n\n- First release.\n\n### v0.1.1\n\n- Fix delete_task problem.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "In memory task schedule support cron tasks, interval tasks and onetime tasks. Using python's asyncio.",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [
        "taskbeat"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7514647c1fffc70046f15d8e21c6d897a6ae971fcfa0ac153871be0afc3ddd61",
                "md5": "505e7883a09dd0c3dde38da2c2585c57",
                "sha256": "3c93be073b1a4afeaa199d92ae11d1fc23fb5f507c6b2f0a1f76492ae0f2c843"
            },
            "downloads": -1,
            "filename": "taskbeat-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "505e7883a09dd0c3dde38da2c2585c57",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5753,
            "upload_time": "2023-10-31T14:56:36",
            "upload_time_iso_8601": "2023-10-31T14:56:36.808025Z",
            "url": "https://files.pythonhosted.org/packages/75/14/647c1fffc70046f15d8e21c6d897a6ae971fcfa0ac153871be0afc3ddd61/taskbeat-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1a04370c230ea292a493295936b640e3beb6a3f8f71dd250ea03e118fe6271cf",
                "md5": "caa6f095738e8a28876f48d3240200b7",
                "sha256": "304f20576b07bcf5793680356f3db5ed1094669980369883f08af6b1ef58c267"
            },
            "downloads": -1,
            "filename": "taskbeat-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "caa6f095738e8a28876f48d3240200b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6018,
            "upload_time": "2023-10-31T14:56:38",
            "upload_time_iso_8601": "2023-10-31T14:56:38.028846Z",
            "url": "https://files.pythonhosted.org/packages/1a/04/370c230ea292a493295936b640e3beb6a3f8f71dd250ea03e118fe6271cf/taskbeat-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-31 14:56:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "taskbeat"
}
        
Elapsed time: 0.25646s