Exemplo n.º 1
0
class Component(object):
    """Base class of business object

    inheritance classes can make use of self.log, self.db and self.util directly without import or instantiating,
    """
    log = RequiredFeature("log")
    db = RequiredFeature("db")
    util = RequiredFeature("util")
Exemplo n.º 2
0
 def send_emails(self,
                 receivers,
                 subject,
                 content,
                 cc=[],
                 bcc=[],
                 attachments=[]):
     email_service = RequiredFeature("email")
     return email_service.send_emails(receivers, subject, content, cc, bcc,
                                      attachments)
Exemplo n.º 3
0
def init_schedule_jobs():
    """Init scheduled jobs

    Note that scheduler job will NOT be enabled in main thread. So the real initialization work are completed in a
    separated thread. Otherwise there might be dead lock in main thread.
    """
    u = RequiredFeature("util")
    if u.is_local():
        return

    import threading

    t = threading.Thread(target=__init_schedule_jobs)
    t.start()
Exemplo n.º 4
0
def init_app():
    """Initialize the application.

    Works including :
        - setting up hackathon factory,
        - register restful API routes
        - initialize scheduled jobs
    """
    init_components()

    from views import init_routes
    init_routes()
    init_schedule_jobs()

    health_check_guacamole = RequiredFeature("health_check_guacamole")
    u = RequiredFeature("util")
    if u.is_local():
        log.debug("guacamole status: %s" % health_check_guacamole.report_health())
Exemplo n.º 5
0
def __init_schedule_jobs():
    """Init scheduled jobs in fact"""
    sche = RequiredFeature("scheduler")
    expr_manager = RequiredFeature("expr_manager")

    # schedule job to check recycle operation
    next_run_time = util.get_now() + timedelta(seconds=10)
    sche.add_interval(feature="expr_manager",
                      method="scheduler_recycle_expr",
                      id="scheduler_recycle_expr",
                      next_run_time=next_run_time,
                      minutes=10)

    # schedule job to pre-allocate environment
    expr_manager.schedule_pre_allocate_expr_job()

    # schedule job to pull docker images automatically
    if not safe_get_config("docker.alauda.enabled", False):
        docker = RequiredFeature("hosted_docker")
        docker.ensure_images()
Exemplo n.º 6
0
def __init_schedule_jobs():
    """Init scheduled jobs in fact"""
    log.debug("init scheduled jobs......")

    sche = RequiredFeature("scheduler")
    hackathon_manager = RequiredFeature("hackathon_manager")
    # host_server_manager = RequiredFeature("docker_host_manager")

    # schedule job to check recycle operation
    next_run_time = util.get_now() + timedelta(seconds=10)
    sche.add_interval(feature="expr_manager",
                      method="scheduler_recycle_expr",
                      id="scheduler_recycle_expr",
                      next_run_time=next_run_time,
                      minutes=10)

    # schedule job to pre-allocate environment
    hackathon_manager.schedule_pre_allocate_expr_job()
Exemplo n.º 7
0
def init_app():
    """Initialize the application.

    Works including :
        - setting up hackathon factory,
        - register restful API routes
        - initialize scheduled jobs
    """
    init_components()

    from views import init_routes
    init_routes()
    init_schedule_jobs()

    health_check_guacamole = RequiredFeature("health_check_guacamole")
    u = RequiredFeature("util")
    if u.is_local():
        log.debug("guacamole status: %s" % health_check_guacamole.report_health())
Exemplo n.º 8
0
def __init_schedule_jobs():
    """Init scheduled jobs in fact"""
    log.debug("init scheduled jobs......")

    util = RequiredFeature("util")
    sche = RequiredFeature("scheduler")
    if not util.is_local():
        hackathon_manager = RequiredFeature("hackathon_manager")
        # host_server_manager = RequiredFeature("docker_host_manager")

        # schedule job to check recycle operation
        next_run_time = util.get_now() + timedelta(seconds=10)
        sche.add_interval(feature="expr_manager",
                          method="scheduler_recycle_expr",
                          id="scheduler_recycle_expr",
                          next_run_time=next_run_time,
                          minutes=10)

        # schedule job to pre-allocate environment
        hackathon_manager.schedule_pre_allocate_expr_job()

        # # schedule job to pull docker images automatically
        # if not safe_get_config("docker.alauda.enabled", False):
        #     docker = RequiredFeature("hosted_docker")
        #     docker.ensure_images()

        # schedule job to pre-create a docker host server VM
        # host_server_manager.schedule_pre_allocate_host_server_job()

    # init the overtime-sessions detection to update users' online status
    sche.add_interval(feature="user_manager",
                      method="check_user_online_status",
                      id="check_user_online_status",
                      minutes=10)
Exemplo n.º 9
0
def before_request():
    user_manager = RequiredFeature("user_manager")
    user_manager.update_user_operation_time()
Exemplo n.º 10
0
 def send_sms(self, receiver, template_id, content):
     sms_service = RequiredFeature("sms")
     return sms_service.send_sms(receiver, template_id, content)
Exemplo n.º 11
0
 def send_voice_verify(self, receiver, content):
     voice_verify_service = RequiredFeature("voice_verify")
     return voice_verify_service.send_voice_verify(receiver, content)
Exemplo n.º 12
0
def before_request():
    user_manager = RequiredFeature("user_manager")
    user_manager.update_user_operation_time()
Exemplo n.º 13
0
def __init_schedule_jobs():
    """Init scheduled jobs in fact"""
    sche = RequiredFeature("scheduler")
    expr_manager = RequiredFeature("expr_manager")

    # schedule job to check recycle operation
    next_run_time = util.get_now() + timedelta(seconds=10)
    sche.add_interval(feature="expr_manager",
                      method="scheduler_recycle_expr",
                      id="scheduler_recycle_expr",
                      next_run_time=next_run_time,
                      minutes=10)

    # schedule job to pre-allocate environment
    expr_manager.schedule_pre_allocate_expr_job()

    # schedule job to pull docker images automatically
    if not safe_get_config("docker.alauda.enabled", False):
        docker = RequiredFeature("hosted_docker")
        docker.ensure_images()
Exemplo n.º 14
0
def __init_schedule_jobs():
    """Init scheduled jobs in fact"""
    log.debug("init scheduled jobs......")

    util = RequiredFeature("util")
    sche = RequiredFeature("scheduler")
    if not util.is_local():
        hackathon_manager = RequiredFeature("hackathon_manager")

        # schedule job to check recycle operation
        next_run_time = util.get_now() + timedelta(seconds=10)
        sche.add_interval(feature="expr_manager",
                          method="scheduler_recycle_expr",
                          id="scheduler_recycle_expr",
                          next_run_time=next_run_time,
                          minutes=10)

        # schedule job to pre-allocate environment
        hackathon_manager.schedule_pre_allocate_expr_job()

        # schedule job to pull docker images automatically
        #if not safe_get_config("docker.alauda.enabled", False):
        #     docker = RequiredFeature("hosted_docker_proxy")
        #     docker.ensure_images()

        # schedule job to pre-create a docker host server VM
        #host_server_manager.schedule_pre_allocate_host_server_job()
    # init the overtime-sessions detection to update users' online status
    sche.add_interval(feature="user_manager",
                      method="check_user_online_status",
                      id="check_user_online_status",
                      minutes=10)
Exemplo n.º 15
0
 def send_emails(self, receivers, subject, content, cc=[], bcc=[], attachments=[]):
     email_service = RequiredFeature("email")
     return email_service.send_emails(receivers, subject, content, cc, bcc, attachments)
Exemplo n.º 16
0
 def send_sms(self, receiver, template_id, content):
     sms_service = RequiredFeature("sms")
     return sms_service.send_sms(receiver, template_id, content)
Exemplo n.º 17
0
 def send_voice_verify(self, receiver, content):
     voice_verify_service = RequiredFeature("voice_verify")
     return voice_verify_service.send_voice_verify(receiver, content)