summaryrefslogtreecommitdiff
path: root/examples/schedulers/async_.py
blob: 5ea9dca36e6fbcc0861a1fb1ca830c7eed271035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import annotations

import logging

import anyio

from apscheduler.schedulers.async_ import AsyncScheduler
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.workers.async_ import AsyncWorker


def say_hello():
    print('Hello!')


async def main():
    async with AsyncScheduler() as scheduler, AsyncWorker(scheduler.data_store):
        await scheduler.add_schedule(say_hello, IntervalTrigger(seconds=1))
        await scheduler.wait_until_stopped()

logging.basicConfig(level=logging.DEBUG)
try:
    anyio.run(main)
except (KeyboardInterrupt, SystemExit):
    pass