Skip to main content

Crontabs for asyncio

Project description

https://travis-ci.org/gawel/aiocron.png?branch=master https://pypip.in/v/aiocron/badge.png https://pypip.in/d/aiocron/badge.png

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

Uploaded Source

Built Distribution

aiocron-0.6-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for aiocron-0.6.tar.gz
Algorithm Hash digest
SHA256 d6d373ad9be024ad1e476052860e04b31c740120abf6e071c870bba87c657f17
MD5 89f7d54161582925379d10b781689357
BLAKE2b-256 a76eab30ad981b3fcdcc391de77ca723425e6c99513b62ac6de82aacbe1d4a3f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiocron-0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b3de3db4c6735220a48e5c6ac1bc399105b0474247c7acf31bf5d6d26cfcf309
MD5 4c5bc09e19f51c23b38c6da7c30174f6
BLAKE2b-256 913b7c298e0b425616ffa311cbea178577df3d45633888de3d435cef1727ae37

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