有用的crontab异步
async-cron的Python项目详细描述
异步cron
此回购协议受计划的影响。
我们提供异步调度程序和异步功能支持
您可以轻松地将此库集成到异步程序中,而无需阻塞
安装
pip安装异步cron
用法示例
importasynciofromasync_cron.jobimportCronJobfromasync_cron.scheduleimportSchedulerasyncdeftest(*args,**kwargs):print(args,kwargs)deftt(*args,**kwargs):print(args,kwargs)msh=Scheduler()myjob=CronJob(name='test',run_total=3).every(5).second.go(test,(1,2,3),name=123)job2=CronJob(name='exact',tolerance=100).at("2019-01-15 16:12").go(tt,(5),age=99)job3=CronJob(name='very_hour').every().hour.at(":44").go(tt,(5),age=99)job3=CronJob(name='hour').every().hour.at(":00").go(tt,(5),age=99)job4=CronJob(name='minute').every(1).minute.go(tt,(5),age=99)job5=CronJob(name='weekday').weekday(2).at("11:18").go(tt,(5),age=99)job6=CronJob(name='monthday').monthday(16).at("11:22").go(tt,(5),age=99)job7=CronJob(name='monthday').every(5).monthday(16).at("11:22").go(tt,(5),age=99)msh.add_job(myjob)msh.add_job(job2)msh.add_job(job3)msh.add_job(job4)msh.add_job(job5)msh.add_job(job6)msh.add_job(job7)# jobload is only a special job,who gen jobs from config# below means, this job load will check every 1 second for cron updates# if any updates found,new job will be add to scheduler# you dont have the direct way to delete jobs# but you can modify the crons total_times to 0 or 1 to delete it# by default,FileJobLoader use MultiThread,you can use MultiProcess by add# thread=Falsef_cron=FileJobLoader(name='f_cron',file_path='t_cron',log_path='.',thread=False)fjob=CronJob(name='fjob',run_total=1).every(1).second.go(f_cron.run,msh)msh.add_job(fjob)loop=asyncio.get_event_loop()try:loop.run_until_complete(msh.start())exceptKeyboardInterrupt:print('exit')
cron文件使用期:
参数用空格分隔。在项目中用逗号分隔
cron | name | job | env | run_times |
---|---|---|---|---|
^{ | test | /bin/python,tt.py | aa=123,bb=345 | 10 |
示例如下:
通用cron
*/1,*,*,*,*,*
测试/bin/python,tt.py aa=123,bb=345 1
删除cron*/1,*,*,*,*,*
测试/bin/python,tt.py aa=123,bb=3450
仅支持cron:*
,10
,*/10
格式。主要完成屏幕
许可证
异步cron是在mit许可下提供的。