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.8.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

aiocron-1.8-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiocron-1.8.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for aiocron-1.8.tar.gz
Algorithm Hash digest
SHA256 48546513faf2eb7901e65a64eba7b653c80106ed00ed9ca3419c3d10b6555a01
MD5 be0f87cf0c5d3012d0dfc0d7f2f8ce25
BLAKE2b-256 c8f2e47f195990b58f13ea8b895498cb28b388716568b53c412e6456fc93f011

See more details on using hashes here.

Provenance

File details

Details for the file aiocron-1.8-py3-none-any.whl.

File metadata

  • Download URL: aiocron-1.8-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for aiocron-1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b6313214c311b62aa2220e872b94139b648631b3103d062ef29e5d3230ddce6d
MD5 845714954c4231bfa63b2d3b92069f52
BLAKE2b-256 ce35f36cb7afa40cdfa6143cb4a81676a1ab0864a1d3f269eda3a694752ae1f1

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