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.