From 56b0d5da2490f87e927cd9b6672e28fbe3679895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B9=E3=82=BF=E3=83=BC=E3=82=AF=E3=82=AE=E3=83=A3?= =?UTF-8?q?=E3=83=B3=E3=82=B0?= Date: Wed, 3 Feb 2021 22:13:10 +0530 Subject: [PATCH] Add apscheduler Examples --- Scheduling-Functions.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Scheduling-Functions.md b/Scheduling-Functions.md index 584233d..d6f1351 100644 --- a/Scheduling-Functions.md +++ b/Scheduling-Functions.md @@ -56,4 +56,35 @@ loop.run_forever() --- -If you don't mind using other libraries, [`aiocron`](https://github.com/gawel/aiocron) is a good option. See https://crontab.guru/ to learn its time syntax. \ No newline at end of file +If you don't mind using other libraries, [`aiocron`](https://github.com/gawel/aiocron) is a good option. See https://crontab.guru/ to learn its time syntax. + +You Can Also Use [`apscheduler`](https://github.com/agronholm/apscheduler), Which is Much Simpler And Much Efficient. + +Here is A Example For Running A Job (Function) Everyday at 6am. + +```python +from apscheduler.schedulers.asyncio import AsyncIOScheduler + +async def greet_me(): + print("Good Morning Midhun") + +scheduler = AsyncIOScheduler() +scheduler.add_job(greet_me, trigger="cron", hour=06) +scheduler.start() +``` + +You Can Also Run A Job At Specific intervals, Here is A Example For it. + +```python +from apscheduler.schedulers.asyncio import AsyncIOScheduler + +async def this_will_run_at_every_one_hour(): + print("One hour has passed") + +scheduler = AsyncIOScheduler() +scheduler.add_job(this_will_run_at_every_one_hour, 'interval', minutes=60) +scheduler.start() +``` +You Can Also Set Custom TimeZones For Running These Functions. +I Like This Because it's More Advance And Better. +Read More About This From [`Here`](https://apscheduler.readthedocs.io/en/stable) \ No newline at end of file