コード例 #1
0
ファイル: messenger.py プロジェクト: fleapx/ghost_sa
def send_auto_noti():
    miss = 1  #初始化没有命中的次数
    while True:
        missTime = 0
        #延迟器,用来降低数据库压力,每次找不到,则增加1秒的重试等待时间。当重试等待超过2分钟后,不再增加重试等待时间。以保证2分钟至少会查询一次。
        projects_result, project_count = select_scheduler_enable_project()
        write_to_log(filename='messenger',
                     defname='send_auto_noti',
                     result='获取启用定时器任务的项目' +
                     (str(project_count) if project_count else '0'))
        for project in projects_result:
            result = select_noti_auto(project=project[0])
            if result[1] > 0:
                miss = 1
                for noti in result[0]:
                    send_manual(project=project[0], noti=noti)
            else:
                miss = miss * 2
                missTime = missTime + 1
                print(project[0] + '暂无自动消息,miss:' + str(miss))
        if missTime == project_count and miss >= 0 and miss <= 120:
            time.sleep(abs(miss))
        elif missTime == project_count and miss > 120:
            time.sleep(120)
        elif missTime < project_count:
            miss = 1
コード例 #2
0
def get_task_day():
    projects_result, project_count = select_scheduler_enable_project()
    write_to_log(filename='scheduler',
                 defname='get_task_day',
                 result='获取启用定时器任务的项目' +
                 (str(project_count) if project_count else '0'))
    for project in projects_result:
        plan_result, plan_count = select_usergroup_jobs_plan(
            project=project[0])
        write_to_log(filename='scheduler',
                     defname='get_task_day',
                     result='查询到项目' + project[0] + '含有可用计划' +
                     (str(plan_count) if plan_count else '0'))
        for plan in plan_result:
            times = get_next_time(timer=plan[2], current_time=int(time.time()))
            for time_1 in times:
                func_loads = json.loads(plan[1])
                func_loads['args']['noti_status'] = plan[4]
                insert_scheduler_job(project=project[0],
                                     group_id=plan[0],
                                     datetime=time_1['time_int'],
                                     data={
                                         'datetime_int':
                                         time_1['time_int'],
                                         'datetime_tuple':
                                         time_1['time_tuple'],
                                         'datetime':
                                         time.strftime("%Y-%m-%d %H:%M:%S",
                                                       time_1['time_tuple']),
                                         'date':
                                         time.strftime("%Y-%m-%d",
                                                       time_1['time_tuple']),
                                         'func':
                                         func_loads
                                     },
                                     priority=plan[3] if plan[3] else 13,
                                     status=16)
                write_to_log(
                    filename='scheduler',
                    defname='get_task_day',
                    result='项目' + str(project[0]) + '计划' + str(plan[0]) +
                    '已添加时间' +
                    time.strftime("%Y-%m-%d %H:%M:%S", time_1['time_tuple']))
            write_to_log(filename='scheduler',
                         defname='get_task_day',
                         result='项目' + str(project[0]) + '计划' + str(plan[0]) +
                         '已添加计划条目' + str(len(times)))
コード例 #3
0
def create_auto_group():
    projects_result, project_count = select_scheduler_enable_project()
    write_to_log(filename='scheduler',
                 defname='create_auto_group',
                 result='获取项目列表' +
                 (str(project_count) if project_count else '0'))
    for project in projects_result:
        result_auto_noti = select_auto_temple_apply_plan(project=project[0])
        # print(result_auto_noti)
        for data_list in result_auto_noti[0]:
            # print(data_list)
            func_data = json.loads(data_list[2])
            # print(func_data)
            id_list = []
            if "default_temple" in func_data and type(
                    func_data["default_temple"]) is list:
                for temple_id in func_data["default_temple"]:
                    id_list.append(temple_id)
            elif "default_temple" in func_data and type(
                    func_data["default_temple"]) is int:
                id_list.append(func_data["default_temple"])
            for tid in id_list:
                send_at = []
                result_temple = select_noti_temple(project=project[0],
                                                   temple_id=tid)
                if result_temple[1] > 0 and result_temple[0][0][2]:
                    args = json.loads(result_temple[0][0][2])
                    if 'meta' in args and 'default_send_time' in args['meta']:
                        print(args['meta']['default_send_time'])
                        send_at_list = get_next_time(
                            timer=args['meta']['default_send_time'],
                            current_time=int(time.time()))
                        # org_data_time_list = get_next_time(timer = args['meta']['default_send_time'],current_time=data_list[3])
                        # if send_at_list == send_at_list :
                        for time_return in send_at_list:
                            send_at.append(time_return['time_int'])
                    elif len(send_at) == 0:
                        send_at.append(int(time.time()))
                    for send_int in send_at:
                        create_noti_group(project=project[0],
                                          temple_id=tid,
                                          user_group_id=data_list[1],
                                          data_id=None,
                                          owner='create_auto_group',
                                          send_at=send_int)