Package: easyschedule
An asynchronus scheduler for python tasks, which uses Cron schedules for precise scheduling recurring tasksDocumenationhttps://easyschedule.readthedocs.io/en/latest/Get StartedpipinstalleasyscheduleimportasynciofromeasyscheduleimportEasySchedulerscheduler=EasyScheduler()default_args={'args':[1,2,3]}weekday_every_minute='* * * * MON-FRI'@scheduler(schedule=weekday_every_minute,default_args=default_args)defweekday_stuff(a,b,c):print(f"a{a}b:{b}c{c}")@scheduler.delayed_start(delay_in_seconds=30)asyncdefdelay_startup():print(f"## startup task - started ##")awaitasyncio.sleep(10)print(f"## startup task - ended ##")@scheduler.shutdown()asyncdefshutdown():print(f"## shutdown task - started ##")awaitasyncio.sleep(10)print(f"## shutdown task - ended ##")@scheduler.once(date_string='2022-03-12 16:18:03')asyncdefnext_year():print(f"That was a long year")asyncdefmain():# start schedulersched=asyncio.create_task(scheduler.start())awaitasyncio.sleep(10)# dynamicly schedule taskwk_end_args={'kwargs':{'count':5}}weekend='30 17-23,0-5 * * SAT,SUN'defweekend_stuff(count:int):for_inrange(count):weekday_stuff(3,4,5)weekday_stuff(5,6,7)scheduler.schedule(weekend_stuff,schedule=weekend,default_args=wk_end_args)awaitschedasyncio.run(main())03-1309:09:25EasySchedulerWARNINGweekday_stuffnext_run_time:2021-03-1500:01:00.14364503-1309:09:25EasySchedulerWARNINGsingletaskdelay_startupscheduledtorunat2021-03-1309:09:55.143337in30.0s03-1309:09:25EasySchedulerWARNINGsingletasknext_yearscheduledtorunat2022-03-1216:18:03in31475317.856636s03-1309:09:35EasySchedulerWARNINGweekend_stuffnext_run_time:2021-03-1317:31:00.15242803-1309:09:48EasySchedulerWARNINGshutdowntaskshutdowntriggeredat2021-03-1309:09:48.937516## shutdown task - started #### shutdown task - ended ##Traceback(mostrecentcalllast):File"test.py",line50,in<module>asyncio.run(main())KeyboardInterruptCron syntax CompatabilityEasySchedule is capable of parsing most cron schedule syntaxMonthlyFirst of month at 11:00 PM0231**DailyEvery 2 Hours0*/2**Weekends OnlyEvery Hour Between 5:30 PM  - 5:30 AM ##3017-23,0-5**SAT,SUNCron GeneratorAn easy & interactive way to build a cron schedule is available viacrontab.guruNote: unsupported syntax (currently)@(non-standard)@hourly
@daily@anuallyScheduluing Single TasksEasySchedule is complete with single task schedulingUsage with 'once' decoratorfromdatetimeimportdatetime,timedeltanext_year=datetime.now()+timedelta(days=365)@scheduler.once(date=next_year)asyncdeffuture_task():## future workpass# current month: 2021-03-13 00:00:00@scheduler.once(date_string='2021-04-13 00:00:00')asyncdefrun_at_date():## future workpass# current month: 2021-03-13 00:00:00@scheduler.once(delta=timedelta(days=3))asyncdefrun_after_delta():## future workpassnow_args={'kwargs':{'work':"Lots of work"}}@scheduler.once(now=True,default_args=now_args)asyncdefrun_now(work):## future workprint(f"starting{work}")passSchedule a task at or near application startupnotify={'kwargs':{'emails':['admin@company.org']}}@scheduler.delayed_start(delay_in_seconds=30,default_args=notify)asyncdefnotify_online(emails:str):message=f"server is operational"awaitsend_emails(message,emails)#something elseasyncdefget_data():returnawaitrequests.get('http://data-source')@scheduler.startup()asyncdefupdate_database():data=awaitget_data()awaitdb.update(data)#something elseSchedule a task to run at application shutdownnotify={'kwargs':{'emails':['admin@company.org']}}@scheduler.shutdown(default_args=notify)asyncdefnotify_shutdown(emails:str):message=f"server is shutting down"awaitsend_emails(message,emails)#something else?