Skip to main content

Crontabs for asyncio

Project description

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

Uploaded Source

Built Distribution

aiocron-2.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiocron-2.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for aiocron-2.1.tar.gz
Algorithm Hash digest
SHA256 1bb65a36aee137e8833592783956e0c7dc478bc3e9273fc2841d5d0c6045e4d2
MD5 43f9be7a6b3123e99c8c14c31a10c43d
BLAKE2b-256 b0cc71fdc16da63deec40da37977541d81052227fc7cbbf2c13358f745f05d86

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiocron-2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for aiocron-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2612b67c552ebc4d24f524fe0316dec30b44f3c5a1d9a3697493d840aa7a5de
MD5 1ccd29d2d01ead627bb05420558781b1
BLAKE2b-256 f28290d3c43e137d06496e0305ce06596a0e36c7cd13c6de986378002c0fd749

See more details on using hashes here.

Supported by

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