Page MenuHomePhabricator

[jobs-api] Split the `*Job` API models into three
Closed, ResolvedPublic

Description

In order to simplify validation (on generated clients specially), we should split the NewJob and DefinedJob models on three each, one for each type of job like NewScheduledJob, etc.

And change the API endpoints to accept a union of those. We should keep using pydantic where possible and use python's multiple inheritance as a way to avoid repeating code, an incomplete example:

class BaseJob(BaseModel):
    cmd: str
    emails: EmailOption = EmailOption.none
    retry: Annotated[int, Field(ge=0, le=5)] = 0


class NamedJob(BaseModel):
    name: str

    @field_validator("name")
    @staticmethod
    def validate_job_name(job_name: str) -> str:
        if not job_name:
            raise TjfValidationError(
                "Job name is required. See the documentation for the naming rules: https://w.wiki/6YL8",
            )
        if not JOBNAME_PATTERN.match(job_name):
            raise TjfValidationError(
                "Invalid job name. See the documentation for the naming rules: https://w.wiki/6YL8",
            )
        if len(job_name) > JOBNAME_MAX_LENGTH:
            raise TjfValidationError(
                f"Invalid job name, it can't be longer than {JOBNAME_MAX_LENGTH} characters. "
                "See the documentation for the naming rules: https://w.wiki/6YL8",
            )
        return job_name


class DefinedScheduledJob(BaseJob, NamedJob): ...

Note that this is a live API, so we should keep it backwards compatible whenever possible.

Related Objects

StatusSubtypeAssignedTask
ResolvedLucasWerkmeister
Resolvedmatmarex
ResolvedLegoktm
ResolvedLegoktm
In Progressdcaro
Resolveddcaro
In Progresskomla
Resolveddcaro
Resolveddcaro
ResolvedRaymond_Ndibe
Opendcaro
OpenNone
In ProgressFeatureRaymond_Ndibe
ResolvedFeatureRaymond_Ndibe
OpenRaymond_Ndibe
ResolvedRaymond_Ndibe
ResolvedRaymond_Ndibe
ResolvedRaymond_Ndibe

Event Timeline

Raymond_Ndibe changed the task status from Open to In Progress.Apr 13 2025, 12:48 AM

group_203_bot_f4d95069bb2675e4ce1fff090c1c1620 opened https://gitlab.wikimedia.org/repos/cloud/toolforge/toolforge-deploy/-/merge_requests/980

jobs-api: bump to 0.0.418-20250925102045-75109675