pyeasycron


Namepyeasycron JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/wyn-ying/pyeasycron
SummaryAn easy way to make function run as cron
upload_time2024-08-19 13:32:02
maintainerNone
docs_urlNone
authorwyn-ying
requires_pythonNone
licenseNone
keywords easycron cron cronjob schedule automation
VCS
bugtrack_url
requirements croniter
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyeasycron

## Brief Intro

An easy way to make function run as cron.

## Installation

``` bash
pip3 install pyeasycron
```

## Usage

### Use as decorator

1. use `easycron.cron` as decorator

    ``` python
    import easycron
    from datetime import datetime

    # Expected run when '*/2 * * * *' is satisfied
    @easycron.cron('*/2 * * * *')
    def func1():
        print(f"in func1: {datetime.now()}")

    # Expected run when one of ['*/5 8 * * *', '7,14,21 9 * * *'] is satisfied
    @easycron.cron(['*/5 8 * * *', '7,14,21 9 * * *'])
    def func2():
        print(f"in func2: {datetime.now()}")

    if __name__ == '__main__':
        easycron.run()
    ```

2. use `easycron.every` as decorator

    ``` python
    import easycron
    from datetime import datetime

    # Expected run every 15 minutes
    @easycron.every(minutes=15)
    def func1():
        print(f"in func1: {datetime.now()}")

    # Expected run every 4 hours
    @easycron.every(hours=4)
    def func2():
        print(f"in func2: {datetime.now()}")

    # Expected run every 2 days
    @easycron.every(days=2)
    def func3():
        print(f"in func3: {datetime.now()}")

    if __name__ == '__main__':
        easycron.run()
    ```

3. use `easycron.every` and `easycron.cron` mixed and stacked

    ``` python
    import easycron
    from datetime import datetime

    # Expected run when '*/3 * * * *' is satisfied
    # **OR** when '*/2 * * * *' is satisfied
    # only run **ONCE** when '*/6 * * * *'
    @easycron.cron('*/3 * * * *')
    @easycron.cron('*/2 * * * *')
    def func3():
        print(f"in func3: {datetime.now()}")


    # Expected run when '*/5 * * * *' is satisfied
    # **OR** every 2 minutes
    # only run **ONCE** when '*/10 * * * *'
    @easycron.every(minutes=2)
    @easycron.cron('*/5 * * * *')
    def func2():
        print(f"in func2: {datetime.now()}")

    # Expected run every 5 minutes
    # OR every 7 minutes
    # only run **ONCE** when meeting every 5*7=35 minutes
    @easycron.every(minutes=5)
    @easycron.every(minutes=7)
    def func1():
        print(f"in func1: {datetime.now()}")

    if __name__ == '__main__':
        easycron.run()
    ```

### Use with concurrency

As default, `easycron.run()` run multi functions in serial way \
(if several functions are triggered at the same time).

If you want to run in concurrency way, just use `concurrency=False` parameter.

``` python
import easycron
from datetime import datetime

@easycron.cron('*/2 * * * *')
def func1():
    print(f"in func1: {datetime.now()}")

if __name__ == '__main__':
    easycron.run(concurrency=False)
```

### Use without block

As default, `easycron.run()` blocks currenct process.

If you want to run in unblock way, just use `block=False` parameter.

``` python
import easycron
from datetime import datetime

@easycron.cron('*/2 * * * *')
def func1():
    print(f"in func1: {datetime.now()}")

if __name__ == '__main__':
    easycron.run(block=False)

    # do other things
    ...
```

### Use register and cancel in a common way

``` python
import easycron
from datetime import timedelta

def func1():
    print(f"in func1: {datetime.now()}")

def func2():
    print(f"in func2: {datetime.now()}")

def func3():
    print(f"in func3: {datetime.now()}")

if __name__ == '__main__':
    easycron.register(func1, interval=timedelta(minutes=3))
    easycron.register(func2, cron_expr='*/2 * * * *')

    easycron.run(block=False)
    # do other things
    ...

    easycron.cancel(func2)
    easycron.register(func3, interval=timedelta(minutes=5))
    # do other things
    ...
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wyn-ying/pyeasycron",
    "name": "pyeasycron",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "easycron, cron, cronjob, schedule, automation",
    "author": "wyn-ying",
    "author_email": "yingwen.wyn@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d1/7f/ef1e2be60eeac45d99596898173d28e7acc6cbfb4dc61f3f8208881193cf/pyeasycron-0.2.1.tar.gz",
    "platform": null,
    "description": "# pyeasycron\n\n## Brief Intro\n\nAn easy way to make function run as cron.\n\n## Installation\n\n``` bash\npip3 install pyeasycron\n```\n\n## Usage\n\n### Use as decorator\n\n1. use `easycron.cron` as decorator\n\n    ``` python\n    import easycron\n    from datetime import datetime\n\n    # Expected run when '*/2 * * * *' is satisfied\n    @easycron.cron('*/2 * * * *')\n    def func1():\n        print(f\"in func1: {datetime.now()}\")\n\n    # Expected run when one of ['*/5 8 * * *', '7,14,21 9 * * *'] is satisfied\n    @easycron.cron(['*/5 8 * * *', '7,14,21 9 * * *'])\n    def func2():\n        print(f\"in func2: {datetime.now()}\")\n\n    if __name__ == '__main__':\n        easycron.run()\n    ```\n\n2. use `easycron.every` as decorator\n\n    ``` python\n    import easycron\n    from datetime import datetime\n\n    # Expected run every 15 minutes\n    @easycron.every(minutes=15)\n    def func1():\n        print(f\"in func1: {datetime.now()}\")\n\n    # Expected run every 4 hours\n    @easycron.every(hours=4)\n    def func2():\n        print(f\"in func2: {datetime.now()}\")\n\n    # Expected run every 2 days\n    @easycron.every(days=2)\n    def func3():\n        print(f\"in func3: {datetime.now()}\")\n\n    if __name__ == '__main__':\n        easycron.run()\n    ```\n\n3. use `easycron.every` and `easycron.cron` mixed and stacked\n\n    ``` python\n    import easycron\n    from datetime import datetime\n\n    # Expected run when '*/3 * * * *' is satisfied\n    # **OR** when '*/2 * * * *' is satisfied\n    # only run **ONCE** when '*/6 * * * *'\n    @easycron.cron('*/3 * * * *')\n    @easycron.cron('*/2 * * * *')\n    def func3():\n        print(f\"in func3: {datetime.now()}\")\n\n\n    # Expected run when '*/5 * * * *' is satisfied\n    # **OR** every 2 minutes\n    # only run **ONCE** when '*/10 * * * *'\n    @easycron.every(minutes=2)\n    @easycron.cron('*/5 * * * *')\n    def func2():\n        print(f\"in func2: {datetime.now()}\")\n\n    # Expected run every 5 minutes\n    # OR every 7 minutes\n    # only run **ONCE** when meeting every 5*7=35 minutes\n    @easycron.every(minutes=5)\n    @easycron.every(minutes=7)\n    def func1():\n        print(f\"in func1: {datetime.now()}\")\n\n    if __name__ == '__main__':\n        easycron.run()\n    ```\n\n### Use with concurrency\n\nAs default, `easycron.run()` run multi functions in serial way \\\n(if several functions are triggered at the same time).\n\nIf you want to run in concurrency way, just use `concurrency=False` parameter.\n\n``` python\nimport easycron\nfrom datetime import datetime\n\n@easycron.cron('*/2 * * * *')\ndef func1():\n    print(f\"in func1: {datetime.now()}\")\n\nif __name__ == '__main__':\n    easycron.run(concurrency=False)\n```\n\n### Use without block\n\nAs default, `easycron.run()` blocks currenct process.\n\nIf you want to run in unblock way, just use `block=False` parameter.\n\n``` python\nimport easycron\nfrom datetime import datetime\n\n@easycron.cron('*/2 * * * *')\ndef func1():\n    print(f\"in func1: {datetime.now()}\")\n\nif __name__ == '__main__':\n    easycron.run(block=False)\n\n    # do other things\n    ...\n```\n\n### Use register and cancel in a common way\n\n``` python\nimport easycron\nfrom datetime import timedelta\n\ndef func1():\n    print(f\"in func1: {datetime.now()}\")\n\ndef func2():\n    print(f\"in func2: {datetime.now()}\")\n\ndef func3():\n    print(f\"in func3: {datetime.now()}\")\n\nif __name__ == '__main__':\n    easycron.register(func1, interval=timedelta(minutes=3))\n    easycron.register(func2, cron_expr='*/2 * * * *')\n\n    easycron.run(block=False)\n    # do other things\n    ...\n\n    easycron.cancel(func2)\n    easycron.register(func3, interval=timedelta(minutes=5))\n    # do other things\n    ...\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "An easy way to make function run as cron",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/wyn-ying/pyeasycron"
    },
    "split_keywords": [
        "easycron",
        " cron",
        " cronjob",
        " schedule",
        " automation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d17fef1e2be60eeac45d99596898173d28e7acc6cbfb4dc61f3f8208881193cf",
                "md5": "6fca851205992d8fe1f696f5d87698b9",
                "sha256": "c79131786b937a43ae80394b6644176dfe59152ce0af78782ae97d1f47f225c9"
            },
            "downloads": -1,
            "filename": "pyeasycron-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6fca851205992d8fe1f696f5d87698b9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5199,
            "upload_time": "2024-08-19T13:32:02",
            "upload_time_iso_8601": "2024-08-19T13:32:02.068371Z",
            "url": "https://files.pythonhosted.org/packages/d1/7f/ef1e2be60eeac45d99596898173d28e7acc6cbfb4dc61f3f8208881193cf/pyeasycron-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-19 13:32:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wyn-ying",
    "github_project": "pyeasycron",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "croniter",
            "specs": []
        }
    ],
    "lcname": "pyeasycron"
}
        
Elapsed time: 0.35507s