Пример #1
0
def set_core(context, config: ConfigManager):
    context["DEBUG"] = config.is_debug_mode
    context["POLYAXON_SERVICE"] = config.service
    context["POLYAXON_ENVIRONMENT"] = config.env
    context["CHART_VERSION"] = config.chart_version
    context["SCHEDULER_ENABLED"] = config.scheduler_enabled
    context["K8S_NAMESPACE"] = config.namespace

    context["FILE_UPLOAD_PERMISSIONS"] = 0o644

    context["WSGI_APPLICATION"] = "polyconf.wsgi.application"
    context["TIME_ZONE"] = config.timezone
    context["LANGUAGE_CODE"] = "en"
    context["LANGUAGES"] = (("en", u"English"), )

    context["USE_I18N"] = True
    context["USE_L10N"] = True
    context["USE_TZ"] = True

    context["INTERNAL_IPS"] = ("127.0.0.1", )
    context["APPEND_SLASH"] = True

    context["ROOT_URLCONF"] = ""

    db_engine = "django.db.backends.postgresql"
    context["DEFAULT_DB_ENGINE"] = db_engine
    db_definition = {
        "ENGINE":
        config.get_string("POLYAXON_DB_ENGINE",
                          is_optional=True,
                          default=db_engine),
        "NAME":
        config.get_string("POLYAXON_DB_NAME"),
        "USER":
        config.get_string("POLYAXON_DB_USER"),
        "PASSWORD":
        config.get_string("POLYAXON_DB_PASSWORD", is_secret=True),
        "HOST":
        config.get_string("POLYAXON_DB_HOST"),
        "PORT":
        config.get_string("POLYAXON_DB_PORT"),
        "ATOMIC_REQUESTS":
        True,
        "CONN_MAX_AGE":
        config.get_int("POLYAXON_DB_CONN_MAX_AGE",
                       is_optional=True,
                       default=None),
    }
    db_options = config.get_dict("POLYAXON_DB_OPTIONS",
                                 is_optional=True,
                                 default={})
    if db_options:
        db_definition["OPTIONS"] = db_options
    context["DATABASES"] = {"default": db_definition}
Пример #2
0
def set_celery(context, config: ConfigManager, routes: Dict):
    context["CELERY_TASK_TRACK_STARTED"] = config.get_boolean(
        "POLYAXON_CELERY_TASK_TRACK_STARTED", is_optional=True, default=True)

    context["CELERY_BROKER_POOL_LIMIT"] = config.get_int(
        "POLYAXON_CELERY_BROKER_POOL_LIMIT", is_optional=True, default=100)

    context["CELERY_BROKER_BACKEND"] = config.broker_backend
    confirm_publish = config.get_boolean("POLYAXON_CELERY_CONFIRM_PUBLISH",
                                         is_optional=True,
                                         default=True)
    context["CELERY_CONFIRM_PUBLISH"] = confirm_publish
    if config.is_rabbitmq_broker and confirm_publish:
        # see https://github.com/celery/celery/issues/5410 for details
        context["CELERY_BROKER_TRANSPORT_OPTIONS"] = {"confirm_publish": True}

    context["CELERY_BROKER_URL"] = config.get_broker_url()

    context["INTERNAL_EXCHANGE"] = config.get_string(
        "POLYAXON_INTERNAL_EXCHANGE", is_optional=True, default="internal")

    result_bucked = config.get_string(
        "POLYAXON_REDIS_CELERY_RESULT_BACKEND_URL",
        is_optional=True,
    )
    if result_bucked:
        context["CELERY_RESULT_BACKEND"] = config.get_redis_url(
            "POLYAXON_REDIS_CELERY_RESULT_BACKEND_URL")

    context["CELERY_WORKER_PREFETCH_MULTIPLIER"] = config.get_int(
        "POLYAXON_CELERY_WORKER_PREFETCH_MULTIPLIER",
        is_optional=True,
        default=4)

    eager_mode = config.get_boolean("POLYAXON_CELERY_TASK_ALWAYS_EAGER")
    context["CELERY_TASK_ALWAYS_EAGER"] = eager_mode
    if eager_mode:
        context["CELERY_BROKER_TRANSPORT"] = "memory"

    context["CELERY_ACCEPT_CONTENT"] = ["application/json"]
    context["CELERY_TASK_SERIALIZER"] = "json"
    context["CELERY_RESULT_SERIALIZER"] = "json"
    context["CELERY_TASK_IGNORE_RESULT"] = True
    context["CELERY_TIMEZONE"] = config.timezone
    context["CELERY_HARD_TIME_LIMIT_DELAY"] = config.get_int(
        "POLYAXON_CELERY_HARD_TIME_LIMIT_DELAY", is_optional=True, default=180)

    context["CELERY_WORKER_MAX_TASKS_PER_CHILD"] = config.get_int(
        "POLYAXON_CELERY_WORKER_MAX_TASKS_PER_CHILD",
        is_optional=True,
        default=100)

    context["CELERY_WORKER_MAX_MEMORY_PER_CHILD"] = config.get_int(
        "POLYAXON_CELERY_WORKER_MAX_MEMORY_PER_CHILD",
        is_optional=True,
        default=400000)

    class Intervals:
        """All intervals are in seconds"""

        OPERATIONS_DEFAULT_RETRY_DELAY = config.get_int(
            "POLYAXON_INTERVALS_OPERATIONS_DEFAULT_RETRY_DELAY",
            is_optional=True,
            default=60,
        )
        OPERATIONS_MAX_RETRY_DELAY = config.get_int(
            "POLYAXON_INTERVALS_OPERATIONS_MAX_RETRY_DELAY",
            is_optional=True,
            default=60 * 60,
        )
        RUNS_SCHEDULER = config.get_int("POLYAXON_INTERVALS_RUNS_SCHEDULER",
                                        is_optional=True,
                                        default=30)

    context["Intervals"] = Intervals
    context["CELERY_TASK_ROUTES"] = routes