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: 6 days 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 (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-12-31T10:04:14.000Z (26 days ago)
- Last Synced: 2025-01-13T00:02:10.593Z (13 days ago)
- Topics: asyncio, cron, cronjob, python, python3
- Language: Python
- Size: 86.9 KB
- Stars: 351
- Watchers: 6
- Forks: 22
- 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.