Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/serialization/pydantic/job.py: 87%
23 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17from datetime import datetime
18from typing import Optional
20from pydantic import BaseModel as BaseModelPydantic
22from airflow.jobs.base_job_runner import BaseJobRunner
25def check_runner_initialized(job_runner: Optional[BaseJobRunner], job_type: str) -> BaseJobRunner:
26 if job_runner is None:
27 raise ValueError(f"In order to run {job_type} you need to initialize the {job_type}Runner first.")
28 return job_runner
31class JobPydantic(BaseModelPydantic):
32 """Serializable representation of the Job ORM SqlAlchemyModel used by internal API."""
34 id: Optional[int]
35 dag_id: Optional[str]
36 state: Optional[str]
37 job_type: Optional[str]
38 start_date: Optional[datetime]
39 end_date: Optional[datetime]
40 latest_heartbeat: datetime
41 executor_class: Optional[str]
42 hostname: Optional[str]
43 unixname: Optional[str]
45 # not an ORM field
46 heartrate: Optional[int]
47 max_tis_per_query: Optional[int]
49 class Config:
50 """Make sure it deals automatically with SQLAlchemy ORM classes."""
52 orm_mode = True