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:

>>> @aiocron.crontab('*/30 * * * *')
... @asyncio.coroutine
... 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)
... @asyncio.coroutine
... def attime():
...     print('run')
>>> attime.start()
>>> asyncio.get_event_loop().run_forever()

Your function still be available at attime.func

You can also yield from a crontab. In this case, your coroutine can accept arguments:

>>> @aiocron.crontab('0 9,10 * * * mon,fri', start=False)
... @asyncio.coroutine
... def attime(i):
...     print('run %i' % i)

>>> @asyncio.coroutine
... def once():
...     try:
...         res = yield from 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:

>>> yield from 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.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiocron-1.1-py2.py3-none-any.whl (5.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: aiocron-1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiocron-1.1.tar.gz
Algorithm Hash digest
SHA256 a375fece3fa6ae6a039d294ccdd02ffda3f6d66c1147c3beda814928aa2ecb14
MD5 cd269563cbacd084a1132e9f80225024
BLAKE2b-256 a8f7202895845d4648a6f144003838c9fe303c650d2b05d0d712c29719f743f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiocron-1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 55653a2042962de5207447d28c9551850fc8f31fba0b6b19295fa9eda6bd3031
MD5 230baa8d864038d8a6a3adbce81084f1
BLAKE2b-256 85932796ad80b152c7e52f29e107aa212966196c98c45918566cc4e0eb18f9c5

See more details on using hashes here.

Supported by

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