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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiocron-1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 ad7d3b9bd88897934ffd18937ff235ab9fb01358280fd40e01461fd5f76348bd
MD5 acb4d58b2808212093e407931d3e1894
BLAKE2b-256 b237b2029981b2d0d6343f586af569502467683fd449ad27dcdf9d96f6ea096f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiocron-1.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f06d7b84b86d6cb7156c01e640b4122da86afaa4873c6bcf79e57c4762e48789
MD5 0d32e52da7108ccbcada4d939b9281a1
BLAKE2b-256 f37fb3088fa213048b1908016f6dc291f5e1a47f384e48c8c3d6440bb7ccbd24

See more details on using hashes here.

Supported by

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