You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
56 lines
1.7 KiB
# coding=utf-8
|
|
"""
|
|
@Author: tangwy
|
|
@FileName: user_cron_pg.py
|
|
@DateTime: 2024/7/09 14:19
|
|
@Description: 定时清洗es数据
|
|
"""
|
|
from __future__ import unicode_literals
|
|
|
|
import random,string
|
|
import traceback,json
|
|
import time
|
|
from datetime import datetime,timedelta
|
|
import calendar
|
|
from uebaMetricsAnalysis.utils.ext_logging import logger
|
|
from uebaMetricsAnalysis.utils.db2json import DBUtils, DBType
|
|
from uebaMetricsAnalysis.utils.base_dataclean_pg import entry
|
|
|
|
JOB_STATUS ={
|
|
"RUNNING":1,
|
|
"FINISH":2,
|
|
"ERROR":3
|
|
}
|
|
|
|
|
|
class UserCron:
|
|
def generate_job_id(self):
|
|
timestamp = int(time.time() * 1000)
|
|
random_letters = ''.join(random.choice(string.ascii_letters) for _ in range(7))
|
|
return str(timestamp) + random_letters
|
|
|
|
#每5分钟执行一次
|
|
def processing(self):
|
|
job_id =self.generate_job_id()
|
|
try:
|
|
logger.info("job:开始执行")
|
|
start,end= DBUtils.get_job_period()
|
|
if start is None or end is None:
|
|
logger.info("job:结束时间大于服务器时间不执行")
|
|
return
|
|
|
|
DBUtils.insert_job_record(job_id,start,end,JOB_STATUS.get("RUNNING"))
|
|
logger.info("job:运行参数:{}".format(start,end))
|
|
|
|
logger.info("job:"+"准备获取es数据")
|
|
entry(start,end)
|
|
logger.info("job:"+"执行完成")
|
|
DBUtils.write_job_status(job_id,JOB_STATUS.get("FINISH"),"")
|
|
except Exception ,e:
|
|
err_info="定时任务执行失败:".format(str(e), traceback.format_exc())
|
|
DBUtils.write_job_status(job_id,JOB_STATUS.get("ERROR"),err_info)
|
|
logger.error(err_info)
|
|
raise
|
|
|
|
if __name__ == '__main__':
|
|
UserCron().processing() |