Package: aiobgjobs
AIOBGJOBS DOCSEn - docsThis library is designed for asynchronous
execution of scheduled tasks.Simple example:importasyncioimportdatetimefromaiobgjobs.dispatcherimportBgDispatcherfromaiobgjobs.typesimportEvery,Repeatsbg_dp=BgDispatcher()@bg_dp.handler_job(every=Every.seconds(15),count_repeats=3)asyncdefsimple_func_every_second():print('Test')@bg_dp.handler_job(every=Every.weekdays.monday(hour=11,minute=40),count_repeats=Repeats.infinity)asyncdefsimple_func_infinity_monday():print('Test2')@bg_dp.handler_job(every=Every.minutes(2),count_repeats=Repeats.infinity)asyncdefsimple_func_every_2_minutes():print('Test3')@bg_dp.handler_job(count_repeats=Repeats.one,datetime_start=datetime.timedelta(minutes=2.0))asyncdefsimple_func_delta_to_start():print('Test4')asyncdefmain():awaitasyncio.create_task(bg_dp.start(relax=.3))if__name__=='__main__':loop=asyncio.new_event_loop()try:loop.run_until_complete(main())exceptKeyboardInterrupt:print('Goodbye!')Example without using decorators:importasyncioimportdatetimefromaiobgjobs.dispatcherimportBgDispatcherfromaiobgjobs.handlersimportHandlerfromaiobgjobs.jobsimportJobfromaiobgjobs.typesimportEvery,Repeatsbg_dp=BgDispatcher()asyncdefsimple_func_every_seconds():print('Test')asyncdefsimple_func_infinity_monday():print('Test2')asyncdefsimple_func_every_2_minutes():print('Test3')asyncdefsimple_func_delta_to_start():print('Test4')bg_dp.register_handler(Handler(job=Job(func=simple_func_every_seconds,name='Job - 1',kwargs=None),count_repeats=3,every=Every.seconds(15)))bg_dp.register_handler(Handler(job=Job(func=simple_func_infinity_monday,name='Job - 2',kwargs=None),count_repeats=Repeats.infinity,every=Every.weekdays.monday()))bg_dp.register_handler(Handler(job=Job(func=simple_func_every_2_minutes,name='Job - 3',kwargs=None),count_repeats=Repeats.infinity,every=Every.minutes(2)))bg_dp.register_handler(Handler(job=Job(func=simple_func_delta_to_start,name='Job - 4',kwargs=None),count_repeats=Repeats.one,datetime_start=datetime.timedelta(minutes=2)))asyncdefmain():awaitasyncio.create_task(bg_dp.start(relax=.3))if__name__=='__main__':loop=asyncio.new_event_loop()try:loop.run_until_complete(main())exceptKeyboardInterrupt:print('Goodbye!')Ru - docsЭта библиотека предназначена для асинхронного
выполнения задач по расписанию.Простой пример:importasyncioimportdatetimefromaiobgjobs.dispatcherimportBgDispatcherfromaiobgjobs.typesimportEvery,Repeatsbg_dp=BgDispatcher()@bg_dp.handler_job(every=Every.seconds(15),count_repeats=3)asyncdefsimple_func_every_second():print('Test')@bg_dp.handler_job(every=Every.weekdays.monday(hour=11,minute=40),count_repeats=Repeats.infinity)asyncdefsimple_func_infinity_monday():print('Test2')@bg_dp.handler_job(every=Every.minutes(2),count_repeats=Repeats.infinity)asyncdefsimple_func_every_2_minutes():print('Test3')@bg_dp.handler_job(count_repeats=Repeats.one,datetime_start=datetime.timedelta(minutes=2.0))asyncdefsimple_func_delta_to_start():print('Test4')asyncdefmain():awaitasyncio.create_task(bg_dp.start(relax=.3))if__name__=='__main__':loop=asyncio.new_event_loop()try:loop.run_until_complete(main())exceptKeyboardInterrupt:print('Goodbye!')Пример без использования декораторов:importasyncioimportdatetimefromaiobgjobs.dispatcherimportBgDispatcherfromaiobgjobs.handlersimportHandlerfromaiobgjobs.jobsimportJobfromaiobgjobs.typesimportEvery,Repeatsbg_dp=BgDispatcher()asyncdefsimple_func_every_seconds():print('Test')asyncdefsimple_func_infinity_monday():print('Test2')asyncdefsimple_func_every_2_minutes():print('Test3')asyncdefsimple_func_delta_to_start():print('Test4')bg_dp.register_handler(Handler(job=Job(func=simple_func_every_seconds,name='Job - 1',kwargs=None),count_repeats=3,every=Every.seconds(15)))bg_dp.register_handler(Handler(job=Job(func=simple_func_infinity_monday,name='Job - 2',kwargs=None),count_repeats=Repeats.infinity,every=Every.weekdays.monday()))bg_dp.register_handler(Handler(job=Job(func=simple_func_every_2_minutes,name='Job - 3',kwargs=None),count_repeats=Repeats.infinity,every=Every.minutes(2)))bg_dp.register_handler(Handler(job=Job(func=simple_func_delta_to_start,name='Job - 4',kwargs=None),count_repeats=Repeats.one,datetime_start=datetime.timedelta(minutes=2)))asyncdefmain():awaitasyncio.create_task(bg_dp.start(relax=.3))if__name__=='__main__':loop=asyncio.new_event_loop()try:loop.run_until_complete(main())exceptKeyboardInterrupt:print('Goodbye!')