Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gawel/aiocron
Crontabs for asyncio
https://github.com/gawel/aiocron
asyncio cron cronjob python python3
Last synced: about 2 months ago
JSON representation
Crontabs for asyncio
- Host: GitHub
- URL: https://github.com/gawel/aiocron
- Owner: gawel
- License: mit
- Created: 2015-02-22T13:50:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-29T20:06:55.000Z (over 1 year ago)
- Last Synced: 2024-06-27T13:32:52.905Z (3 months ago)
- Topics: asyncio, cron, cronjob, python, python3
- Language: Python
- Size: 84 KB
- Stars: 332
- Watchers: 6
- Forks: 20
- Open Issues: 6
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-starts - gawel/aiocron - Crontabs for asyncio (Python)
README
================================================
aiocron - Crontabs for asyncio
================================================.. image:: https://img.shields.io/pypi/v/aiocron.svg
:target: https://pypi.python.org/pypi/aiocron
.. image:: https://img.shields.io/pypi/dm/aiocron.svg
:target: https://pypi.python.org/pypi/aiocronUsage
=====``aiocron`` provide a decorator to run function at time::
>>> import aiocron
>>> import asyncio
>>>
>>> @aiocron.crontab('*/30 * * * *')
... async def attime():
... print('run')
...
>>> asyncio.get_event_loop().run_forever()You can also use it as an object::
>>> @aiocron.crontab('1 9 * * 1-5', start=False)
... async def attime():
... print('run')
...
>>> attime.start()
>>> asyncio.get_event_loop().run_forever()Your function still be available at ``attime.func``
You can also await a crontab. In this case, your coroutine can accept
arguments::>>> @aiocron.crontab('0 9,10 * * * mon,fri', start=False)
... async def attime(i):
... print('run %i' % i)
...
>>> async def once():
... try:
... res = await attime.next(1)
... except Exception as e:
... print('It failed (%r)' % e)
... else:
... print(res)
...
>>> asyncio.get_event_loop().run_forever()Finally you can use it as a sleep coroutine. The following will wait until
next hour::>>> await crontab('0 * * * *').next()
If you don't like the decorator magic you can set the function by yourself::
>>> cron = crontab('0 * * * *', func=yourcoroutine, start=False)
Notice that unlike standard unix crontab you can specify seconds at the 6th
position.``aiocron`` use `croniter `_. Refer to
it's documentation to know more about crontab format.