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.
48 lines
1.7 KiB
48 lines
1.7 KiB
# coding=utf-8
|
|
"""
|
|
@Author: fu-zhe
|
|
@FileName: user_cron.py
|
|
@DateTime: 2024/5/23 14:19
|
|
@Description: 用户相关的定时任务 全量获取,对已有数据进行先删除后写入 周期一天
|
|
"""
|
|
from __future__ import unicode_literals
|
|
|
|
import collections
|
|
import json
|
|
import time,datetime
|
|
from datetime import datetime, timedelta
|
|
import calendar
|
|
from uebaMetricsAnalysis.utils.ext_logging import logger
|
|
from uebaMetricsAnalysis.utils.base_dataclean import entry
|
|
|
|
class UserCron:
|
|
def get_index_name():
|
|
baseIndex ="a_ueba_analyse_"
|
|
# 获取当前日期
|
|
now = datetime.now()
|
|
|
|
# 转到上一个月
|
|
last_month = now - timedelta(days=calendar.monthrange(now.year, now.month)[1])
|
|
last_month_year = last_month.year
|
|
last_month_month = last_month.month
|
|
|
|
if last_month_month < 10:
|
|
last_month_month = '0' + str(last_month_month)
|
|
return baseIndex + str(last_month_year) + '_' + str(last_month_month)
|
|
|
|
def processing(self):
|
|
try:
|
|
#写入的索引 按月创建,注意跨天的场景
|
|
write_index= self.get_index_name()
|
|
read_index ="bsa_traffic*"
|
|
|
|
#任务执行时间是每天 凌晨12点
|
|
#查询的范围 开始时间前一天的0点0分0秒,结束时间是 前一天的23.59.59秒
|
|
start = datetime.datetime.now()
|
|
end = datetime.datetime.now()
|
|
|
|
entry(write_index,read_index,start,end)
|
|
logger.info("start processing")
|
|
except Exception ,e:
|
|
logger.error("定时任务执行失败:".format(str(e), traceback.format_exc()))
|
|
raise
|
|
|