Need help with aiocron?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

gawel
158 Stars 9 Forks MIT License 79 Commits 4 Opened issues

Description

Crontabs for asyncio

Services available

!
?

Need anything else?

Contributors list

# 41,841
CSS
irc-bot
jQuery
Shell
58 commits
# 1,850
mypy
phoenix...
python3
github-...
4 commits
# 5,594
Python
telegra...
teletho...
Telegra...
1 commit
# 335,367
JavaScr...
mtproto
teletho...
Shell
1 commit

================================================

aiocron - Crontabs for asyncio

.. image:: https://travis-ci.org/gawel/aiocron.svg?branch=master :target: https://travis-ci.org/gawel/aiocron .. 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/aiocron

Usage

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.