Django通过Json配置文件分配多个定时任务

python 复制代码
	def load_config():
	    with open("rule.json", 'rb')as f:
	        config = json.load(f)
	    return config
	def job(task_name, config, time_interval):
	# 	...	通过task_name判断进行操作
		if task_name == 'get_data_times':
			pass

	def main():
	    config = load_config()
	
	    for task_name, task_value in config.items():
	        # 循环配置文件中配置的时间 启动定时任务			多少秒运行一次
	        if task_name.startswith('get_data') or task_name.startswith('get_internet'):
	            time_interval = int(task_value.replace('s', ''))
	            schedule.every(time_interval).seconds.do(job, task_name, config, time_interval)
	        elif task_name.endswith('_time'):
	        	# 多少分钟运行一次
	            time_interval = int(task_value.replace('min', ''))
	            time_intervals = time_interval + 1
	            schedule.every(time_interval).minutes.do(job, task_name, config, time_intervals)
			# 可以设置多个 时分秒 周月星期一到星期天 at
	    def run_jobs():
	        while True:
	            schedule.run_pending()
	            time.sleep(1)
	
	    thread = threading.Thread(target=run_jobs)
	    thread.start()
	
	if __name__ == '__main__':
	    import django, os
	    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "QsManagement.settings")
	    django.setup()
	    from app01.logger import logger
	    from app01.models import ComputerStatus, AlarmInfo, InterNetSpeed, WindowsError, ProductionLine, Machine, MachineType
	    from app01.methods import get_ip
	    main()

json配置文件 通过配置文件设置阈值,到达指定阈值报警

python 复制代码
	{
	  "get_data_times": "3min",
	  "get_internet_times": "3min",
	  "get_windows_error_time": "3min",
	
	  "cpu_time" : "1min",
	  "cpu_rate" : "90%",
	
	  "memory_time" : "1min",
	  "memory_rate" : "75%",
	
	  "gpu_time" : "1min",
	  "gpu_rate" : "50%",
	
	  "disk_times": "3min",
	  "C_disk_space": "50G",
	  "D_disk_space": "30G",
	  "E_disk_space": "50G",
	  "F_disk_space": "50G",
	  "G_disk_space": "50G",
	
	  "cpu_temperature":  "50度",
	  "temperature_time": "1min",
	
	  "internet_speed": "200ms",
	  "internet_time" : "1min"
	}
相关推荐
aiotto资源分享2 天前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
菜鸟~noob2332 天前
[AI]间章:系列走到这里,聊聊后面的规划、造卡需要的软件平台,以及为什么我要先暂停更新
人工智能·python·fpga开发·django·pygame
一起学安全技术3 天前
拆大模型 10|结构化输出:让模型返回数据,而不是一段话
人工智能·语言模型·json
用户298698530143 天前
在 Python 中把 Word 文档转换为 JSON 的三种实现方式
python·json·api
承渊政道5 天前
【Python编程—从入门到实践】(用户账户:给Django网站装上登录系统,让每个人拥有自己的学习笔记)
python·学习·pycharm·django
FRing035 天前
vue2干货总结10(json-server、vant-ui、postcss插件、axios二次封装、图形验证码、toast轻提示)
开发语言·前端·vue.js·ui·json·vue2·postcss
承渊政道5 天前
【Python编程—从入门到实践】(设置样式并部署:给Django网站换新装,把学习笔记发布到互联网)
python·学习·pycharm·django
用户298698530145 天前
使用 Python 将 JSON 转换为 Word 文档的实践指南
python·json·api
九英里路6 天前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
wuyk5556 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel