Skip to main content

Crontabs for asyncio

Project description

https://travis-ci.org/gawel/aiocron.svg?branch=master https://img.shields.io/pypi/v/aiocron.svg https://img.shields.io/pypi/dm/aiocron.svg

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiocron-1.4.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

aiocron-1.4-py2.py3-none-any.whl (4.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aiocron-1.4.tar.gz.

File metadata

  • Download URL: aiocron-1.4.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.4.2 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for aiocron-1.4.tar.gz
Algorithm Hash digest
SHA256 89d598f6cfa07d344144cb87378ea285aadcf4c731becb575f275ac6c1153b5e
MD5 45da399561c87a58a78ef2d5a9a2a38e
BLAKE2b-256 d3b8e8ca4ea96e03dc16dd8613b2a63c2247b295ae0c5ef31fefa82fdb688dc7

See more details on using hashes here.

Provenance

File details

Details for the file aiocron-1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: aiocron-1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.4.2 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for aiocron-1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3146674bd8f0ad5de5525d865eac02a4cc2207e15ff564f72288f4b900268ac7
MD5 54dd577f7a7847da79ecdd55343130fe
BLAKE2b-256 00246973e5d23e35ac1fe1722ebcf2742dc1a93eef1477e711a10c2aed1f7699

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page