有哪个网站可以查别人做没做过牢吗网站服务器维护工具
有哪个网站可以查别人做没做过牢吗,网站服务器维护工具,邢台市教育局官网,如何制作网站后台定时校正需求: mysql和redis两个系统, mysql增加数据成功, redis未必添加成功, 这样两个系统的数据可能出现偏差, 所以需要定期对mysql和redis的数据进行同步解决方案: 每天执行一次定时任务, 让mysql数据和redis数据进行同步crontab是linux系统一个内置命令, 依赖于linux系统,…定时校正需求: mysql和redis两个系统, mysql增加数据成功, redis未必添加成功, 这样两个系统的数据可能出现偏差, 所以需要定期对mysql和redis的数据进行同步解决方案: 每天执行一次定时任务, 让mysql数据和redis数据进行同步crontab是linux系统一个内置命令, 依赖于linux系统, 无动态管理任务(取消/暂停/修改任务配置)使用场景: 适合于普通的静态任务apscheduler独立的定时器程序, 可以方便的管理定时任务使用场景: 需要动态生成/管理任务, 如下单后30分钟可有效期安装 pip install apscheduler支持三种触发器date 只执行一次interval 周期执行 参数 时间间隔cron 周期执行 参数 时间调度器 Scheduler负责管理定时任务BlockingScheduler: 作为独立进程时使用from apscheduler.schedulers.blocking import BlockingSchedulerscheduler BlockingScheduler()scheduler.start() # 此处程序会发生阻塞BackgroundScheduler: 在框架程序(如Django、Flask)中使用from apscheduler.schedulers.background import BackgroundSchedulerscheduler BackgroundScheduler()scheduler.start() # 此处程序不会发生阻塞执行器 executors在定时任务该执行时以进程或线程方式执行任务ThreadPoolExecutorfrom apscheduler.executors.pool import ThreadPoolExecutorThreadPoolExecutor(max_workers)ThreadPoolExecutor(20) # 最多20个线程同时执行使用方法executors {default: ThreadPoolExecutor(20)}scheduler BackgroundScheduler(executorsexecutors)ProcessPoolExecutorfrom apscheduler.executors.pool import ProcessPoolExecutorProcessPoolExecutor(max_workers)ProcessPoolExecutor(5) # 最多5个进程同时执行使用方法executors {default: ProcessPoolExecutor(3)}scheduler BackgroundScheduler(executorsexecutors)触发器 Trigger指定定时任务执行的时机1) date 在特定的时间日期执行from datetime import date# 在2019年11月6日00:00:00执行sched.add_job(my_job, date, run_datedate(2009, 11, 6))# 在2019年11月6日16:30:05sched.add_job(my_job, date, run_datedatetime(2009, 11, 6, 16, 30, 5))sched.add_job(my_job, date, run_date2009-11-06 16:30:05)# 立即执行sched.add_job(my_job, date)sched.start()2) interval 经过指定的时间间隔执行weeks (int) – number of weeks to waitdays (int) – number of days to waithours (int) – number of hours to waitminutes (int) – number of minutes to waitseconds (int) – number of seconds to waitstart_date (datetime|str) – starting point for the interval calculationend_date (datetime|str) – latest possible date/time to trigger ontimezone (datetime.tzinfo|str) – time zone to use for the date/time calculationsfrom datetime import datetime# 每两小时执行一次sched.add_job(job_function, interval, hours2)# 在2010年10月10日09:30:00 到2014年6月15日的时间内每两小时执行一次sched.add_job(job_function, interval, hours2, start_date2010-10-10 09:30:00, end_date2014-06-15 11:00:00)3) cron 按指定的周期执行year (int|str) – 4-digit yearmonth (int|str) – month (1-12)day (int|str) – day of the (1-31)week (int|str) – ISO week (1-53)day_of_week (int|str) – number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun)hour (int|str) – hour (0-23)minute (int|str) – minute (0-59)second (int|str) – second (0-59)start_date (datetime|str) – earliest possible date/time to trigger on (inclusive)end_date (datetime|str) – latest possible date/time to trigger on (inclusive)timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations(defaults to scheduler timezone)# 在6、7、8、11、12月的第三个周五的00:00, 01:00, 02:00和03:00 执行sched.add_job(job_function, cron, month6-8,11-12, day3rd fri, hour0-3)# 在2014年5月30日前的周一到周五的5:30执行sched.add_job(job_function, cron, day_of_weekmon-fri, hour5, minute30, end_date2014-05-30)任务管理方式1job scheduler.add_job(myfunc, interval, minutes2) # 添加任务job.remove() # 删除任务job.pause() # 暂定任务job.resume() # 恢复任务方式2scheduler.add_job(myfunc, interval, minutes2, idmy_job_id) # 添加任务scheduler.remove_job(my_job_id) # 删除任务scheduler.pause_job(my_job_id) # 暂定任务scheduler.resume_job(my_job_id) # 恢复任务调整任务调度周期job.modify(max_instances6, nameAlternate name)scheduler.reschedule_job(my_job_id, triggercron, minute*/5)停止APScheduler运行scheduler.shutdown()代码import timefrom apscheduler.schedulers.background import BackgroundSchedulerfrom apscheduler.executors.pool import ThreadPoolExecutor# 创建执行器 用于支持多进程/多线程executor ThreadPoolExecutor(max_workers5)# 创建调度器scheduler BackgroundScheduler(executors{default: executor})def func1(name, age):print(name, age)# 添加任务# date 只执行一次# scheduler.add_job(func1, date, run_date2019-08-29 14:53:40, args[zs, 30])# interval 周期执行 参数是时间间隔# scheduler.add_job(func1, interval, seconds10, args[zs, 30])# cron 周期执行 参数是时间 每月1号3点会执行一次# scheduler.add_job(func1, cron, day1, hour3, args[zs, 30])# 秒针每次到30时执行一次scheduler.add_job(func1, cron, second30, args[zs, 30])# 启动调度器scheduler.start()while True:time.sleep(24 * 60 * 60)
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/89526.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!