Ejemplo n.º 1
0
def _notify_scheduler(event):
    if event.code == EVENT_SCHEDULER_START:
        content = 'scheduler start now %s' % get_now()
    elif event.code == EVENT_SCHEDULER_SHUTDOWN:
        content = 'scheduler shutdown now %s' % get_now()
    else:
        content = 'unknown'
    mail_sender.send_email(config.data['system_admin_email_list'],
                           'scheduler notify', content)
Ejemplo n.º 2
0
def _check_and_invite_coach():
    """
    教练开班邀请定时任务,主要处理:
    1. 教练邀请过期检查及处理;
    2. 教练自动邀请;
    3. 如果教练已找齐,设置邀请完成
    每日早上6点到晚上12点,每分钟运行一次
    :return:
    """
    with db_session_manager.with_session() as db_session:
        manager = CoachInviteManager(db_session)
        num = manager.process_expired_invite()
        logger.info('process %d invites' % num)

    day = get_now().replace(days=+3).date()

    with db_session_manager.with_session() as db_session:
        manager = ClassAllocationManager(db_session)
        task_manager = ClassCreateTaskManager(db_session)
        tasks = task_manager.get_need_invite_coach_tasks(day)
        for task in tasks:
            coaches = manager.search_coach(task)
            logger.info('task(%s): %s' % (task.id, coaches))

    with db_session_manager.with_session() as db_session:
        task_manager = ClassCreateTaskManager(db_session)
        invite_manager = CoachInviteManager(db_session)
        tasks = task_manager.get_inviting_tasks(day)
        for task in tasks:
            invites = invite_manager.get_task_success_invite(task.id)
            if len(invites) >= task.new_class_num:
                task_manager.set_task_to_invite_complete(task.id)
                logger.info('task: %d invite complete.' % task.id)
Ejemplo n.º 3
0
def _calculate_enrollment_schedule():
    logger.info('correct coach status')
    with db_session_manager.with_session() as db_session:
        manager = ClassTemplateManager(db_session)
        today = format_date(get_now())
        manager.calculate_enrollment_schedule(today)

    logger.info('correct coach status end.')
Ejemplo n.º 4
0
def _class_enrollment_schedule_calculate():
    """
    计算学生报名情况,每天凌晨2点执行一次
    :return:
    """
    with db_session_manager.with_session() as db_session:
        today_date = get_now().strftime('%Y-%m-%d')
        manager = ClassTemplateManager(db_session)
        manager.calculate_enrollment_schedule(today_date)
Ejemplo n.º 5
0
def _daily_check_expired_class():
    """
    关闭过期班级
    """
    with db_session_manager.with_session() as db_session:
        manager = ClassSuperviseManager(db_session)
        day = get_now().date()
        manager.auto_close_expired_classes(day)
        logger.info('daily check expired class')
Ejemplo n.º 6
0
def _daily_notify_coach_continue_class_start():
    """
    提前7天、3天提醒教练续接班即将开课
    """
    with db_session_manager.with_session() as db_session:
        manager = ContinueClassManager(db_session)
        day = get_now().date()
        manager.notify_coach_continue_class_start(day)
        logger.info('daily check coach continue class')
Ejemplo n.º 7
0
def _daily_notify_no_continue_class_coaches():
    """
    提醒教务:已短信提醒教练设置续接班3次 当前续接班仍为0的教练
    """
    with db_session_manager.with_session() as db_session:
        manager = ContinueClassManager(db_session)
        day = get_now().date()
        manager.notify_admin_no_set_continue_class_coaches(day)
        logger.info('daily check coach continue class')
Ejemplo n.º 8
0
def _daily_check_coach_continue_class():
    """
    提醒教练设置续接班
    """
    with db_session_manager.with_session() as db_session:
        manager = ContinueClassManager(db_session)
        day = get_now().date()
        manager.auto_check(day)
        logger.info('daily check coach continue class')
Ejemplo n.º 9
0
 def __attach_file(virtual_file, file_name=None):
     if not file_name:
         file_name = get_now().format('YYYY-MM-DD') + '.csv'
     message = MIMEMultipart()
     msg = MIMEBase('application', 'octet-stream')
     msg.set_payload(virtual_file.getvalue())
     encoders.encode_base64(msg)
     msg.add_header('Content-Disposition', 'attachment', filename=file_name)
     message.attach(msg)
     return message
Ejemplo n.º 10
0
def _daily_check_fail_change_coach_task():
    """
    检查自动换老师失败任务
    :return:
    """
    with db_session_manager.with_session() as db_session:
        manager = ClassCoachManager(db_session)
        day = get_now().replace(days=+6).date()
        manager.notify_fail_change_class(day)
        logger.info('daily check fail change coach task')
Ejemplo n.º 11
0
def _auto_change_coach():
    """
    自动更换可用时段结束的班级教练,自动找教练添加更换教练任务、发邀请。
    :return:
    """
    with db_session_manager.with_session() as db_session:
        manager = ClassCoachManager(db_session)
        days = [
            get_now().replace(days=+7).date(),
            get_now().replace(days=+8).date(),
        ]
        for class_day in days:
            class_list = manager.get_need_change_coach_class_list(class_day)
            for class_info in class_list:
                result = manager.start_change_coach(class_info, class_day)
                logger.info('change class (%s): %s' % (class_info.id, result))
            if not class_list:
                logger.info('day (%s) no class need change coach'
                            % format_date(class_day))
Ejemplo n.º 12
0
def _daily_complete_change_coach():
    """
    自动完成教练更换,将当天需要替换的教练完成替换。
    :return:
    """
    with db_session_manager.with_session() as db_session:
        manager = ClassCoachManager(db_session)
        day = get_now().date()
        process_count = manager.daily_complete_change_task(day)
        logger.info('daily complete change coach process count: %s'
                    % process_count)
Ejemplo n.º 13
0
def _send_everyday_reservation():
    """
    获取前一天报名学员的信息
    (约课日期、学员账号、姓名、手机、时段、课程开始日期、课程结束日期)
    """
    with db_session_manager.with_session() as db_session:
        today = get_now()
        start_time = format_date(today.replace(days=-1))
        end_time = format_date(today)
        manager = ServiceReservationManager(db_session)
        manager.send_reservation_by_time(start_time, end_time)
        logger.info('daily_send_everyday_reservation')
Ejemplo n.º 14
0
def run(parameter):
    today = get_now()
    if len(parameter) == 1:
        start_time = format_date(parameter[0])
        end_time = format_date(today, 'YYYY-MM-DD HH:mm:ss')
    else:
        start_time = format_date(today.replace(days=-1))
        end_time = format_date(today)

    with db_session_manager.with_session() as db_session:
        manager = ServiceReservationManager(db_session)
        logger.info('start send reservation from {} to {}.'.format(start_time, end_time))
        manager.send_reservation_by_time(start_time, end_time)
        logger.info('end send reservation.')
Ejemplo n.º 15
0
def _class_create():
    """
    清除班级过期学员、释放教师可用时段、创建组班任务,每日凌晨2点执行一次
    :return:
    """
    with db_session_manager.with_session() as db_session:
        manager = ClassSuperviseManager(db_session)
        manager.process_expired_student()

    with db_session_manager.with_session() as db_session:
        manager = TemporarySubstituteCoachTaskManager(db_session)
        manager.process_need_free_available_time_task()

    with db_session_manager.with_session() as db_session:
        manager = ClassAllocationManager(db_session)
        manager.create_tasks(get_now().replace(days=+3).date())