Ejemplo n.º 1
0
def create_scheduler_jobs_manual():
    #手动创建分群任务
    project = get_url_params('project')
    plan_id = get_url_params('plan_id')
    send_at = get_url_params('send_at') if get_url_params('send_at') else int(
        time.time())
    password = get_url_params('password')
    if password == admin.admin_password and request.method == 'POST':
        try:
            count = 0
            plan_result, plan_count = select_usergroup_jobs_plan_manual(
                project=project, plan_id=plan_id)
            for plan in plan_result:
                times = get_next_time(current_time=int(send_at))
                for time_1 in times:
                    insert_result, insert_count = insert_scheduler_job(
                        project=project,
                        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':
                            json.loads(plan[1])
                        },
                        priority=plan[3] if plan[3] else 13,
                        status=16)
                    write_to_log(
                        filename='api_noti',
                        defname='create_scheduler_jobs_manual',
                        result='项目' + str(project) + '计划' +
                        str(plan[0]) + '已添加时间' + time.strftime(
                            "%Y-%m-%d %H:%M:%S", time_1['time_tuple']))
                    count = count + insert_count
            returnjson = {'result': 'success', 'insert_count': count}
            return jsonify(returnjson)
        except Exception:
            error = traceback.format_exc()
            write_to_log(filename='api_noti',
                         defname='create_scheduler_jobs_manual',
                         result=error)
            returnjson = {'result': 'fail', 'error': error}
            return jsonify(returnjson)
Ejemplo n.º 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)))
Ejemplo n.º 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)