Example #1
0
    def get(self, *args, **kwargs):
        platforms = Platform.all()

        return jsonify({
            "meta": {
                "skip": 0,
                "limit": 100,
                "count": len(platforms)
            },
            "items": platforms,
        })
Example #2
0
def does_platform_allow_worker_to_run(worker, running_tasks, task):
    """ whether worker can now run task according to platform limitations """
    platform = task["config"].get("platform")
    if not platform:
        return True
    nb_running_on = sum([
        1 for running_task in running_tasks
        if running_task["config"].get("platform") == platform
    ])
    if nb_running_on == 0:
        return True
    platform_limit = worker.get("platforms", {}).get(
        platform, Platform.get_max_concurrent_for(platform))
    return True if platform_limit is None else nb_running_on < platform_limit
Example #3
0
            Offliner.sotoki: SotokiFlagsSchema,
            Offliner.nautilus: NautilusFlagsSchema,
            Offliner.ted: TedFlagsSchema,
            Offliner.openedx: OpenedxFlagsSchema,
            Offliner.zimit: ZimitFlagsSchema,
        }.get(offliner, Schema)

    @validates_schema
    def validate(self, data, **kwargs):
        if "task_name" in data and "flag" in data:
            schema = self.get_offliner_schema(data["task_name"])
            data["flags"] = schema.load(data["flags"])


class ScheduleSchema(Schema):
    name = fields.String(required=True, validate=validate_schedule_name)
    language = fields.Nested(LanguageSchema(), required=True)
    category = fields.String(required=True, validate=validate_category)
    periodicity = fields.String(required=True, validate=validate_periodicity)
    tags = fields.List(fields.String(validate=validate_not_empty),
                       required=True,
                       default=[])
    enabled = fields.Boolean(required=True, truthy=[True], falsy=[False])
    config = fields.Nested(ScheduleConfigSchema(), required=True)


PlatformsLimitSchema = Schema.from_dict({
    platform: fields.Integer(required=False, validate=validate_platform_value)
    for platform in Platform.all()
})
Example #4
0
validate_not_empty = validate.Length(min=1)
validate_role = validate.OneOf(ROLES.keys())
validate_cpu = validate.Range(min=0)
validate_memory = validate.Range(min=0)
validate_disk = validate.Range(min=0)
validate_lang_code = validate.Length(min=2, max=3)
validate_output = validate.Equal("/output")
validate_category = validate.OneOf(ScheduleCategory.all())
validate_warehouse_path = validate.OneOf(
    ScheduleCategory.all_warehouse_paths())
validate_offliner = validate.OneOf(Offliner.all())
validate_status = validate.OneOf(TaskStatus.all())
validate_event = validate.OneOf(TaskStatus.all_events())
validate_worker_name = validate.Length(min=3)
validate_periodicity = validate.OneOf(SchedulePeriodicity.all())
validate_platform = validate.OneOf(Platform.all())
validate_platform_value = validate.Range(min=0)


def validate_multiple_of_100(value):
    return value % 100 == 0


# reusable fields
skip_field = fields.Integer(required=False,
                            missing=0,
                            validate=validate.Range(min=0))
limit_field_20_500 = fields.Integer(required=False,
                                    missing=20,
                                    validate=validate.Range(min=0, max=500))
limit_field_20_200 = fields.Integer(required=False,