|
|
@@ -26,15 +26,19 @@ class RunTasks():
|
|
|
# 检查 task_interval 字段是否存在并且是正整数
|
|
|
if 'task_interval' in task_config_data and isinstance(task_config_data['task_interval'], int) and \
|
|
|
task_config_data['task_interval'] > 0:
|
|
|
- # 读取 execution_time 字段的值
|
|
|
- execution_time_str = task_config_data['execution_time']
|
|
|
- execution_time_dt = datetime.strptime(execution_time_str, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
- # 计算新的 execution_time
|
|
|
- new_execution_time = execution_time_dt + timedelta(minutes=task_config_data['task_interval'])
|
|
|
+ if task_config_data['task_interval'] != 0:
|
|
|
+ # 读取 execution_time 字段的值
|
|
|
+ execution_time_str = task_config_data['execution_time']
|
|
|
+ execution_time_dt = datetime.strptime(execution_time_str, '%Y-%m-%d %H:%M:%S')
|
|
|
+
|
|
|
+ # 计算新的 execution_time
|
|
|
+ new_execution_time = execution_time_dt + timedelta(minutes=task_config_data['task_interval'])
|
|
|
|
|
|
- # 更新 execution_time 字段
|
|
|
- task_config_data['execution_time'] = new_execution_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ # 更新 execution_time 字段
|
|
|
+ task_config_data['execution_time'] = new_execution_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ else:
|
|
|
+ task_config_data['execution_times'] = 0
|
|
|
|
|
|
# 更新最新完成时间
|
|
|
task_config_data['completion_time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
@@ -95,7 +99,7 @@ class RunTasks():
|
|
|
"target_selector": "目标css选择器",
|
|
|
"result_value": "返回值,留空",
|
|
|
"execution_time": "9999-12-31 23:59:59",
|
|
|
- "task_interval": "任务执行间隔",
|
|
|
+ "task_interval": 0,
|
|
|
"completion_time": "完成时间,留空",
|
|
|
"execution_times": 0,
|
|
|
"logs": "日志,留空"
|
|
|
@@ -130,8 +134,7 @@ class RunTasks():
|
|
|
print(f'开始执行任务 {task_name}')
|
|
|
|
|
|
# 打开浏览器, 获取目标页面数据
|
|
|
- # browser_result_data = CryptoCrawler(url=target_url, selector=target_selector).main()
|
|
|
- browser_result_data = '网页返回值'
|
|
|
+ browser_result_data = CryptoCrawler(url=target_url, selector=target_selector).main()
|
|
|
|
|
|
# 1, 如果有数据, 则更新 task_config_data 的 result_value 字段, 并且 execution_times 字段减 1
|
|
|
# 2, 如果 task_interval 这个字段是正整数, 并且大于 0, 则读取 execution_time 字段的值, 然后加上 task_interval
|