pa_api.xmlapi.types.operations.job

 1import enum
 2import logging
 3from datetime import time
 4from typing import Annotated, Optional
 5
 6from pydantic import ConfigDict, Field, PlainValidator
 7
 8from pa_api.xmlapi.types.utils import (
 9    Datetime,
10    String,
11    XMLBaseModel,
12    parse_datetime,
13    parse_time,
14)
15
16
17def parse_tdeq(d):
18    if "null" in d:
19        return None
20    try:
21        return parse_time(d)
22    except Exception as e:
23        logging.debug(e)
24    return parse_datetime(d)
25
26
27def parse_progress(progress):
28    try:
29        return float(progress)
30    except Exception as e:
31        logging.debug(f"{e} => Fallback to datetime parsing")
32
33    # When finished, progress becomes the date of the end
34    if parse_datetime(progress):
35        return 100.0
36    return None
37
38
39Progress = Annotated[float, PlainValidator(parse_progress)]
40Time = Annotated[time, PlainValidator(parse_tdeq)]
41
42
43class JobResult(enum.Enum):
44    OK = "OK"
45    FAIL = "FAIL"
46
47
48class Job(XMLBaseModel):
49    model_config = ConfigDict(
50        # https://docs.pydantic.dev/2.0/api/alias_generators/
51        # alias_generator=lambda name: name.replace("-", "_")
52    )
53    # TODO: Use pydantic
54    type: str
55    tenq: Optional[Datetime] = None
56    tdeq: Optional[Time] = None
57    id: str = ""
58    user: String = ""
59    status: str = ""
60    queued: bool = False
61    stoppable: bool = False
62    result: str = ""
63    tfin: Optional[Datetime] = None
64    description: String = ""
65    position_in_queue: int = Field(alias="positionInQ", default=-1)
66    progress: Progress = 0.0
67    details: String = ""
68    warnings: String = ""
def parse_tdeq(d):
18def parse_tdeq(d):
19    if "null" in d:
20        return None
21    try:
22        return parse_time(d)
23    except Exception as e:
24        logging.debug(e)
25    return parse_datetime(d)
def parse_progress(progress):
28def parse_progress(progress):
29    try:
30        return float(progress)
31    except Exception as e:
32        logging.debug(f"{e} => Fallback to datetime parsing")
33
34    # When finished, progress becomes the date of the end
35    if parse_datetime(progress):
36        return 100.0
37    return None
Progress = typing.Annotated[float, PlainValidator(func=<function parse_progress>, json_schema_input_type=typing.Any)]
Time = typing.Annotated[datetime.time, PlainValidator(func=<function parse_tdeq>, json_schema_input_type=typing.Any)]
class JobResult(enum.Enum):
44class JobResult(enum.Enum):
45    OK = "OK"
46    FAIL = "FAIL"

An enumeration.

OK = <JobResult.OK: 'OK'>
FAIL = <JobResult.FAIL: 'FAIL'>
class Job(pa_api.xmlapi.types.utils.XMLBaseModel):
49class Job(XMLBaseModel):
50    model_config = ConfigDict(
51        # https://docs.pydantic.dev/2.0/api/alias_generators/
52        # alias_generator=lambda name: name.replace("-", "_")
53    )
54    # TODO: Use pydantic
55    type: str
56    tenq: Optional[Datetime] = None
57    tdeq: Optional[Time] = None
58    id: str = ""
59    user: String = ""
60    status: str = ""
61    queued: bool = False
62    stoppable: bool = False
63    result: str = ""
64    tfin: Optional[Datetime] = None
65    description: String = ""
66    position_in_queue: int = Field(alias="positionInQ", default=-1)
67    progress: Progress = 0.0
68    details: String = ""
69    warnings: String = ""

!!! abstract "Usage Documentation" Models

A base class for creating Pydantic models.

Attributes: __class_vars__: The names of the class variables defined on the model. __private_attributes__: Metadata about the private attributes of the model. __signature__: The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
__pydantic_core_schema__: The core schema of the model.
__pydantic_custom_init__: Whether the model has a custom `__init__` function.
__pydantic_decorators__: Metadata containing the decorators defined on the model.
    This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
__pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
    __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__: The name of the post-init method for the model, if defined.
__pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel].
__pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model.
__pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model.

__pydantic_fields__: A dictionary of field names and their corresponding [`FieldInfo`][pydantic.fields.FieldInfo] objects.
__pydantic_computed_fields__: A dictionary of computed field names and their corresponding [`ComputedFieldInfo`][pydantic.fields.ComputedFieldInfo] objects.

__pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra]
    is set to `'allow'`.
__pydantic_fields_set__: The names of fields explicitly set during instantiation.
__pydantic_private__: Values of private attributes set on the model instance.
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

type: str
tenq: Optional[Annotated[datetime.datetime, PlainValidator(func=<function parse_datetime at 0x7f4bd7a6e710>, json_schema_input_type=Any)]]
tdeq: Optional[Annotated[datetime.time, PlainValidator(func=<function parse_tdeq at 0x7f4bd79e5870>, json_schema_input_type=Any)]]
id: str
user: typing.Annotated[str, BeforeValidator(func=<function ensure_str at 0x7f4bd793fac0>, json_schema_input_type=PydanticUndefined)]
status: str
queued: bool
stoppable: bool
result: str
tfin: Optional[Annotated[datetime.datetime, PlainValidator(func=<function parse_datetime at 0x7f4bd7a6e710>, json_schema_input_type=Any)]]
description: typing.Annotated[str, BeforeValidator(func=<function ensure_str at 0x7f4bd793fac0>, json_schema_input_type=PydanticUndefined)]
position_in_queue: int
progress: typing.Annotated[float, PlainValidator(func=<function parse_progress at 0x7f4bd79e49d0>, json_schema_input_type=typing.Any)]
details: typing.Annotated[str, BeforeValidator(func=<function ensure_str at 0x7f4bd793fac0>, json_schema_input_type=PydanticUndefined)]
warnings: typing.Annotated[str, BeforeValidator(func=<function ensure_str at 0x7f4bd793fac0>, json_schema_input_type=PydanticUndefined)]