提交 d1ad54d7 authored 作者: zw.wang's avatar zw.wang

feat: [tasks] 定时任务

上级 c0ce7650
......@@ -80,18 +80,23 @@ def query(cursor_dict=False):
@query(cursor_dict=True)
def get_camera_info(cursor, conn):
sql = '''
select id as camera_id,
name as camera_name,
point_index_code,
'131331' as event_type,
concat('common_video_', mod(service_type, 2), '.',
'video_data_motion_', mod(biz_type, 8)) as 'db_table',
ai_config_support, device_code, service_type, biz_type,
region_path_name
from camera_info
join camera_ai_config cac
select
id as camera_id,
name as camera_name,
point_index_code,
'131331' as event_type,
concat('common_video_', mod(service_type, 2), '.',
'video_data_motion_', mod(biz_type, 8)
) as 'db_table',
ai_config_support, device_code, service_type, biz_type,
region_path_name
from camera_info
join camera_ai_config cac
on camera_info.id = cac.camera_info_id
where biz_type is not null and is_valid = 1
where
`is_valid` = 1
and biz_type is not null
and `point_index_code` is not null
order by create_time;
'''
cursor.execute(sql)
......
......@@ -28,7 +28,18 @@ text = """ ## isc视频录制巡检报告
● 当前在线摄像头个数:{} \n
● 当前离线摄像头个数:{} \n
● 摄像头状态巡检时间:{} \n
================ \n
最近半小时内重试情况:\n
{} \n
"""
retry_text = """
● 摄像头序列号: {} \n
● 重试次数:{} \n
● 摄像头在线状态:{} \n
++=== \n
"""
daily_text = """ ## {}日报, 共{}路摄像头
......@@ -55,7 +66,7 @@ class Tasks:
'apscheduler.timezone': TIMEZONE})
schedulers.add_job(self.run_moniter_online, 'interval', minutes=3, seconds=10)
schedulers.add_job(self.run_moniter_hour, 'cron', minute='0,30')
schedulers.add_job(self.run_moniter_daily, 'cron', hour=10, minute=30)
schedulers.add_job(self.run_moniter_daily, 'cron', hour=9, minute=30)
schedulers.start()
@staticmethod
......@@ -73,8 +84,8 @@ class Tasks:
'camera_index': camera['point_index_code']
},
'fields': {
'value': online_info.get('online', 0),
'collect_time': online_info['collectTime']
'value': online_info.get('online', -1),
'collect_time': online_info.get('collectTime')
},
'time': datetime.utcnow()
})
......@@ -122,6 +133,23 @@ class Tasks:
collect_time = datetime.strptime(
collect_time, '%Y-%m-%dT%H:%M:%S.%fZ')
res = influxdb.query(
"select count(value) from one_week.video_retry_count "
"where time > '{}' group by camera_code;"
.format(datetime.utcnow() - timedelta(minutes=30))
)
video_retry_count = []
for (_, camera_code), count in res.items():
video_retry_count.append({**camera_code, **next(count)})
sub_text = ''
for retry_count in sorted(video_retry_count, key=lambda x: x['count'], reverse=True)[:3]:
online_info = api_helper.get_camera_online(retry_count['camera_code'])
sub_text += retry_text.format(
retry_count['camera_code'],
retry_count['count'],
online_info.get('online', -1)
)
mobiles = None
if online_count <= 3:
mobiles = ['15131601294']
......@@ -131,7 +159,8 @@ class Tasks:
len(pipe.keys(PROCESSING_CAMERA_KEY.format('*'))),
get_time_str(pre_video_duration['value']),
online_count, offline_count,
collect_time.astimezone(tz).strftime('%Y-%m-%d %H:%M:%S')
collect_time.astimezone(tz).strftime('%Y-%m-%d %H:%M:%S'),
sub_text
), mobiles)
@staticmethod
......@@ -142,13 +171,13 @@ class Tasks:
headers = [
'区域路径',
'摄像头序列号', '摄像头名称', 'IndexCode',
'总时长', '完成', '失败', '未处理', '未知', '在线时长', '离线时长'
'总时长', '完成', '失败', '未处理', '未知', '在线时长', '离线时长', '存储'
]
columns = [
'region_path_name',
'device_code', 'camera_name', 'point_index_code',
'total', 'done', 'failed', 'untreated', 'unknown',
'online_duration', 'offline_duration'
'online_duration', 'offline_duration', 'db_table'
]
query_str = '''
......@@ -239,5 +268,5 @@ if __name__ == '__main__':
log_init(__name__, False)
t = Tasks()
# t.start()
# t.run_moniter_hour()
t.run_moniter_online()
t.run_moniter_hour()
# t.run_moniter_online()
......@@ -24,7 +24,7 @@ requires = [
setuptools.setup(
name='isc-video-record',
version='1.0.0a22',
version='1.0.0b1',
description='ISC motion detection playback video stream recording service.',
long_description=long_description,
long_description_content_type='text/markdown',
......
......@@ -66,20 +66,19 @@ for device in devices.get('list'):
if online_info['online'] != 1:
continue
print('直播预览接口: ', client.get_camera_preview_url(camera_code).get('url'))
print('直播预览接口: ', client.get_camera_preview_url(camera_code, protocol='rtmp').get('url'))
print('-------------')
res = client.get_camera_quality(camera_code)
camera_quality = res.get('list') or []
camera_quality = camera_quality[0] if len(camera_quality) > 0 else {}
text = ''
for key, value in camera_quality.items():
desc = desc_dict.get(key)
if not desc:
continue
name = desc.get('cn', key)
value = desc.get('value', {}).get(str(value) or '-1', value)
text += '{}: {}\n'.format(name, value)
print(text)
# print('-------------')
# res = client.get_camera_quality(camera_code)
# camera_quality = res.get('list') or []
# camera_quality = camera_quality[0] if len(camera_quality) > 0 else {}
# text = ''
# for key, value in camera_quality.items():
# desc = desc_dict.get(key)
# if not desc:
# continue
# name = desc.get('cn', key)
# value = desc.get('value', {}).get(str(value) or '-1', value)
# text += '{}: {}\n'.format(name, value)
# print(text)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论