コード例 #1
0
ファイル: __init__.py プロジェクト: ups216/open-hackathon
def init_voice_verify():
    """ initial voice verify service
    Example for config.py:
    "voice_verify": {
        "enabled": True,
        "provider": "rong_lian",
        "rong_lian": {
            ... ...
        }
    }
    """
    provider_name = safe_get_config("voice_verify.provider", None)
    enabled = safe_get_config("voice_verify.enabled", False)
    if not enabled:
        log.warn("voice verify disabled")
        factory.provide("voice_verify", DisabledVoiceVerify)
    elif provider_name and safe_get_config("voice_verify." + provider_name,
                                           None):
        log.warn("Voice verify initialized to:" + provider_name)
        # if provider other than Ronglian is supported, update following lines
        factory.provide("voice_verify", RonglianVoiceVerify)
    else:
        log.warn(
            "either voice verify provider name or provider config is missing, Please check your configuration"
        )
        raise ConfigurationException("voice_verify.provider")
コード例 #2
0
def init_sms():
    """ initial SMS service """
    provider_name = safe_get_config("sms.provider", None)
    enabled = safe_get_config("sms.enabled", False)
    if not enabled:
        log.warn("SMS service disabled")
        factory.provide("sms", DisabledSms)
    elif provider_name and safe_get_config("sms." + provider_name, None):
        log.warn("SMS initialized to:" + provider_name)
        # if provider other than ChinaTelecom is supported, update following lines
        factory.provide("sms", ChinaTelecomSms)
    else:
        log.warn("Either SMS provider name or provider config is missing, Please check your configuration")
        raise ConfigurationException("sms.provider")
コード例 #3
0
ファイル: __init__.py プロジェクト: zwwhdls/open-hackathon
def init_sms():
    """ initial SMS service """
    provider_name = safe_get_config("sms.provider", None)
    enabled = safe_get_config("sms.enabled", False)
    if not enabled:
        log.warn("SMS service disabled")
        factory.provide("sms", DisabledSms)
    elif provider_name and safe_get_config("sms." + provider_name, None):
        log.warn("SMS initialized to:" + provider_name)
        # if provider other than ChinaTelecom is supported, update following lines
        factory.provide("sms", ChinaTelecomSms)
    else:
        log.warn("Either SMS provider name or provider config is missing, Please check your configuration")
        raise ConfigurationException("sms.provider")
コード例 #4
0
ファイル: __init__.py プロジェクト: IdearHui/open-hackathon
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()

    # 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()
コード例 #5
0
def init_hackathon_storage():
    """Add storage implementation to hackathon factory

    The type of storage is configured by ""storage.type"" in config.py which is 'local' by default
    """
    from hackathon.storage import AzureStorage, LocalStorage

    storage_type = safe_get_config("storage.type", "azure")
    if storage_type == "azure":
        factory.provide("storage", AzureStorage)
    else:
        factory.provide("storage", LocalStorage)
コード例 #6
0
ファイル: __init__.py プロジェクト: mshubian/open-hackathon
def init_hackathon_storage():
    """Add storage implementation to hackathon factory

    The type of storage is configured by ""storage.type"" in config.py which is 'local' by default
    """
    from hackathon.storage import AzureStorage, LocalStorage

    storage_type = safe_get_config("storage.type", "azure")
    if storage_type == "azure":
        factory.provide("storage", AzureStorage)
    else:
        factory.provide("storage", LocalStorage)
コード例 #7
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.
    """
    if safe_get_config("environment", "local") == "local":
        return

    import threading

    t = threading.Thread(target=__init_schedule_jobs)
    t.start()
コード例 #8
0
ファイル: __init__.py プロジェクト: mshubian/open-hackathon
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.
    """
    if safe_get_config("environment", "local") == "local":
        return

    import threading

    t = threading.Thread(target=__init_schedule_jobs)
    t.start()
コード例 #9
0
def init_voice_verify():
    """ initial voice verify service
    Example for config.py:
    "voice_verify": {
        "enabled": True,
        "provider": "rong_lian",
        "rong_lian": {
            ... ...
        }
    }
    """
    provider_name = safe_get_config("voice_verify.provider", None)
    enabled = safe_get_config("voice_verify.enabled", False)
    if not enabled:
        log.warn("voice verify disabled")
        factory.provide("voice_verify", DisabledVoiceVerify)
    elif provider_name and safe_get_config("voice_verify." + provider_name, None):
        log.warn("Voice verify initialized to:" + provider_name)
        # if provider other than Ronglian is supported, update following lines
        factory.provide("voice_verify", RonglianVoiceVerify)
    else:
        log.warn("either voice verify provider name or provider config is missing, Please check your configuration")
        raise ConfigurationException("voice_verify.provider")
コード例 #10
0
ファイル: __init__.py プロジェクト: ups216/open-hackathon
def init_hackathon_storage():
    """Add storage implementation to hackathon factory

    The type of storage is configured by ""storage.type"" in config.py which is 'local' by default
    """
    from hackathon.storage import AzureStorage, LocalStorage

    storage_type = safe_get_config("storage.type", "azure")
    if storage_type == "azure":
        # init BlobServiceAdapter first since AzureStorage depends on it. And accountKey must be included in config file
        from hackathon.hazure import BlobServiceAdapter
        factory.provide("azure_blob_service", BlobServiceAdapter)
        factory.provide("storage", AzureStorage)
    else:
        factory.provide("storage", LocalStorage)
コード例 #11
0
ファイル: __init__.py プロジェクト: IdearHui/open-hackathon
def init_hackathon_storage():
    """Add storage implementation to hackathon factory

    The type of storage is configured by ""storage.type"" in config.py which is 'local' by default
    """
    from hackathon.storage import AzureStorage, LocalStorage

    storage_type = safe_get_config("storage.type", "azure")
    if storage_type == "azure":
        # init BlobServiceAdapter first since AzureStorage depends on it. And accountKey must be included in config file
        from hackathon.hazure import BlobServiceAdapter
        factory.provide("azure_blob_service", BlobServiceAdapter)
        factory.provide("storage", AzureStorage)
    else:
        factory.provide("storage", LocalStorage)
コード例 #12
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()
コード例 #13
0
ファイル: __init__.py プロジェクト: ups216/open-hackathon
from hackathon_response import *
from hackathon_exception import *
from log import log
from context import Context
from database import db_session

__all__ = [
    "app",
    "Context",
    "RequiredFeature",
    "Component",
]

# initialize flask and flask restful
app = Flask(__name__)
app.config['SECRET_KEY'] = safe_get_config("app.secret_key", "secret_key")


class HackathonApi(Api):
    """Customize Api to give a chance to handle exceptions in framework level.
    So that our restful APIs will always respond with code 200 even if Exception thrown and not caught in our codes

    We can raise HTTPException and it's inheritances directly in components, they will be caught here. Now we have two
    ways to response with error:
        - return bad_request("some message")
        - raise Bad_Request("some message")
    You can decide to use either way ,they are of the same.
    """
    def handle_error(self, e):
        log.error(e)
        if isinstance(e, HTTPException):
コード例 #14
0
ファイル: __init__.py プロジェクト: IdearHui/open-hackathon
from hackathon_scheduler import HackathonScheduler
from hackathon_response import *
from log import log
from context import Context

__all__ = [
    "app",
    "Context",
    "RequiredFeature",
    "Component",
]


# initialize flask and flask restful
app = Flask(__name__)
app.config['SECRET_KEY'] = safe_get_config("app.secret_key", "secret_key")


class HackathonApi(Api):
    """Customize Api to give a chance to handle exceptions in framework level.
    So that our restful APIs will always respond with code 200 even if Exception thrown and not caught in our codes

    We can raise HTTPException and it's inheritances directly in components, they will be caught here. Now we have two
    ways to response with error:
        - return bad_request("some message")
        - raise Bad_Request("some message")
    You can decide to use either way ,they are of the same.
    """

    def handle_error(self, e):
        log.error(e)