Skip to content

Commit f7336bc

Browse files
committed
fix linting
1 parent 7a3bdf5 commit f7336bc

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

metadata-ingestion/examples/ml/create_ml.py

+41-35
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import random
22
import time
33
from dataclasses import dataclass
4-
from typing import Iterable, List, Optional, Union
4+
from typing import Dict, Iterable, List, Optional, Union
55

66
import datahub.metadata.schema_classes as models
77
from datahub.api.entities.datajob import DataFlow, DataJob
@@ -29,6 +29,13 @@ class ContainerKeyWithId(ContainerKey):
2929
id: str
3030

3131

32+
@dataclass
33+
class RunInfo:
34+
start_time: int
35+
duration: int
36+
result: InstanceRunResult
37+
38+
3239
@dataclass
3340
class Container:
3441
key: ContainerKeyWithId
@@ -222,32 +229,32 @@ def generate_pipeline(
222229
start_time = end_time - (30 * 24 * 60 * 60 * 1000)
223230
run_timestamps = [start_time + (i * 5 * 24 * 60 * 60 * 1000) for i in range(5)]
224231

225-
run_dict = {
226-
"run_1": {
227-
"start_time": run_timestamps[0],
228-
"duration": 45,
229-
"result": InstanceRunResult.SUCCESS,
230-
},
231-
"run_2": {
232-
"start_time": run_timestamps[1],
233-
"duration": 60,
234-
"result": InstanceRunResult.FAILURE,
235-
},
236-
"run_3": {
237-
"start_time": run_timestamps[2],
238-
"duration": 55,
239-
"result": InstanceRunResult.SUCCESS,
240-
},
241-
"run_4": {
242-
"start_time": run_timestamps[3],
243-
"duration": 70,
244-
"result": InstanceRunResult.SUCCESS,
245-
},
246-
"run_5": {
247-
"start_time": run_timestamps[4],
248-
"duration": 50,
249-
"result": InstanceRunResult.FAILURE,
250-
},
232+
run_dict: Dict[str, RunInfo] = {
233+
"run_1": RunInfo(
234+
start_time=run_timestamps[0],
235+
duration=45,
236+
result=InstanceRunResult.SUCCESS,
237+
),
238+
"run_2": RunInfo(
239+
start_time=run_timestamps[1],
240+
duration=60,
241+
result=InstanceRunResult.FAILURE,
242+
),
243+
"run_3": RunInfo(
244+
start_time=run_timestamps[2],
245+
duration=55,
246+
result=InstanceRunResult.SUCCESS,
247+
),
248+
"run_4": RunInfo(
249+
start_time=run_timestamps[3],
250+
duration=70,
251+
result=InstanceRunResult.SUCCESS,
252+
),
253+
"run_5": RunInfo(
254+
start_time=run_timestamps[4],
255+
duration=50,
256+
result=InstanceRunResult.FAILURE,
257+
),
251258
}
252259

253260
for i, (model_name, model_description) in enumerate(
@@ -340,25 +347,24 @@ def generate_pipeline(
340347
)
341348

342349
# Generate start and end events
343-
start_time_millis = int(run_dict[run_id]["start_time"])
344-
duration_minutes = int(run_dict[run_id]["duration"])
350+
run_info = run_dict[run_id]
351+
start_time_millis = run_info.start_time
352+
duration_minutes = run_info.duration
345353
end_time_millis = start_time_millis + (duration_minutes * 60000)
346-
result = run_dict[run_id]["result"]
347-
if not isinstance(result, InstanceRunResult):
348-
raise TypeError(f"Expected InstanceRunResult, got {type(result)}")
354+
result = run_info.result
349355

350356
result_type = (
351357
"SUCCESS" if result == InstanceRunResult.SUCCESS else "FAILURE"
352358
)
353359

354360
yield from data_process_instance.start_event_mcp(
355-
start_timestamp_millis=int(start_time_millis)
361+
start_timestamp_millis=start_time_millis
356362
)
357363
yield from data_process_instance.end_event_mcp(
358-
end_timestamp_millis=int(end_time_millis),
364+
end_timestamp_millis=end_time_millis,
359365
result=result,
360366
result_type=result_type,
361-
start_timestamp_millis=int(start_time_millis),
367+
start_timestamp_millis=start_time_millis,
362368
)
363369

364370
# Model

0 commit comments

Comments
 (0)