Skip to main content

Schedule asyncio coroutines

Project description

everytime - Schedule asyncio coroutines

TLDR

@schedule(every.other.wednesday.at(hour=12), loop)
async def do_something():
    ...

to schedule do_something() every second Wednesday at 12:00 on the asyncio.EventLoop called loop. loop has to be running for that.

Full Example

import asyncio
from everytime import *

loop = asyncio.new_event_loop()

async def greet():
    print("Hello")

every(5).seconds.do(greet, loop)
loop.run_forever()

Schedule with do()

You can schedule actions with the do function.

async def greet():
    print("Hello")

every(5).seconds.do(greet, loop)

Schedule with decorators

If you prefer, you can decorate your action with an everytime expression.

@schedule(every(5).seconds, loop)
async def greet():
    print("Hello")

Schedule custom times

@schedule accepts datetime iterables. The following schedules work:

@schedule([datetime.fromisoformat('2022-11-01T12:00:00'), datetime.fromisoformat('2023-01-01T12:00:00')], loop)

@schedule(itertools.islice(every.day, 5), loop)

@schedule(map(lambda _: datetime.now() + timedelta(seconds=1), sys.stdin), loop)

Supported Expressions

Quantification

Every time unit can be quantified by every, every.other or every(n):

  • every.second
  • every.other.second
  • every(5).seconds

Supported time units

The supported time units are

  • millisecond
  • second
  • minute
  • hour
  • day
  • week

Weekdays

Also, weekdays monday through sunday are supported. every.wednesday starts on the next Wednesday. If today is a Wednesday, every.wednesday starts today.

Specific time of the day

day and the weekdays can be scheduled for a specific time of the day:

every.day.at(hour=12, minute=15)

(Note that hour is 24-hour based)

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

everytime-0.2.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

everytime-0.2.0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

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