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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiocron-1.6.tar.gz
  • Upload date:
  • Size: 16.0 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.6.tar.gz
Algorithm Hash digest
SHA256 21f00288e9993f4e44ae2e51d4301b7822512962fc900b59317d11299c125a6a
MD5 70d562f54b35bb83269a6c03dfc52b36
BLAKE2b-256 f3b5a9654aa7df2847cd9bf5131b5f2fdae299efe9fdf0fa8384bc62a83ba023

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: aiocron-1.6-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ab451380199ef09757f95085220cd34bf6970239bdb77863e3413ee08297fcc5
MD5 f131145ad84d2f54f37844d31f111c91
BLAKE2b-256 cf6b23e9bdb406b5493c66be596de61c3920a3dfb4e0555160e92ea529180d1a

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