|
13 | 13 | from __lib import optimus_sla_miss_notify, SuperKubernetesPodOperator, \ |
14 | 14 | SuperExternalTaskSensor, ExternalHttpSensor |
15 | 15 |
|
16 | | -from __lib import JOB_START_EVENT_NAME, \ |
17 | | - JOB_END_EVENT_NAME, \ |
18 | | - log_start_event, \ |
19 | | - log_success_event, \ |
| 16 | +from __lib import log_success_event, \ |
20 | 17 | log_retry_event, \ |
21 | 18 | log_failure_event, \ |
22 | | - EVENT_NAMES, \ |
23 | | - log_job_end, log_job_start |
| 19 | + EVENT_NAMES |
24 | 20 |
|
25 | 21 | SENSOR_DEFAULT_POKE_INTERVAL_IN_SECS = int(Variable.get("sensor_poke_interval_in_secs", default_var=15 * 60)) |
26 | 22 | SENSOR_DEFAULT_TIMEOUT_IN_SECS = int(Variable.get("sensor_timeout_in_secs", default_var=15 * 60 * 60)) |
|
69 | 65 | ] |
70 | 66 | ) |
71 | 67 |
|
72 | | -publish_job_start_event = PythonOperator( |
73 | | - task_id = JOB_START_EVENT_NAME, |
74 | | - python_callable = log_job_start, |
75 | | - provide_context=True, |
76 | | - depends_on_past=False, |
77 | | - dag=dag |
78 | | - ) |
79 | | - |
80 | | -publish_job_end_event = PythonOperator( |
81 | | - task_id = JOB_END_EVENT_NAME, |
82 | | - python_callable = log_job_end, |
83 | | - provide_context=True, |
84 | | - trigger_rule= 'all_success', |
85 | | - depends_on_past=False, |
86 | | - dag=dag |
87 | | - ) |
88 | | - |
89 | 68 | {{$baseTaskSchema := .Job.Task.Unit.Info -}} |
90 | 69 | {{- $setCPURequest := not (empty .Metadata.Resource.Request.CPU) -}} |
91 | 70 | {{- $setMemoryRequest := not (empty .Metadata.Resource.Request.Memory) -}} |
|
299 | 278 |
|
300 | 279 | # upstream sensors -> base transformation task |
301 | 280 | {{- range $i, $t := $.Job.Dependencies }} |
302 | | -publish_job_start_event >> wait_{{ $t.Job.Name | replace "-" "__dash__" | replace "." "__dot__" }} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
| 281 | +wait_{{ $t.Job.Name | replace "-" "__dash__" | replace "." "__dot__" }} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
303 | 282 | {{- end}} |
304 | 283 | {{- range $_, $t := $.Job.ExternalDependencies.HTTPDependencies }} |
305 | | -publish_job_start_event >> wait_{{ $t.Name }} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
| 284 | +wait_{{ $t.Name }} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
306 | 285 | {{- end}} |
307 | 286 | {{- range $_, $dependency := $.Job.ExternalDependencies.OptimusDependencies}} |
308 | 287 | {{ $identity := print $dependency.Name "-" $dependency.ProjectName "-" $dependency.JobName }} |
309 | | -publish_job_start_event >> wait_{{ $identity | replace "-" "__dash__" | replace "." "__dot__" }} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
| 288 | +wait_{{ $identity | replace "-" "__dash__" | replace "." "__dot__" }} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
310 | 289 | {{- end}} |
311 | 290 | {{if and (not $.Job.Dependencies) (not $.Job.ExternalDependencies.HTTPDependencies) (not $.Job.ExternalDependencies.OptimusDependencies)}} |
312 | 291 | # if no sensor and dependency is configured |
313 | | -publish_job_start_event >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
| 292 | +transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
314 | 293 | {{end}} |
315 | 294 | # post completion hook |
316 | | -transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} >> publish_job_end_event |
| 295 | +transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
317 | 296 |
|
318 | 297 | # set inter-dependencies between task and hooks |
319 | 298 | {{- range $_, $task := .Job.Hooks }} |
320 | 299 | {{- $hookSchema := $task.Unit.Info }} |
321 | 300 | {{- if eq $hookSchema.HookType $.HookTypePre }} |
322 | | -publish_job_start_event >> hook_{{$hookSchema.Name | replace "-" "__dash__"}} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
| 301 | +hook_{{$hookSchema.Name | replace "-" "__dash__"}} >> transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} |
323 | 302 | {{- end -}} |
324 | 303 | {{- if eq $hookSchema.HookType $.HookTypePost }} |
325 | | -transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} >> hook_{{$hookSchema.Name | replace "-" "__dash__"}} >> publish_job_end_event |
| 304 | +transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} >> hook_{{$hookSchema.Name | replace "-" "__dash__"}} |
326 | 305 | {{- end -}} |
327 | 306 | {{- if eq $hookSchema.HookType $.HookTypeFail }} |
328 | | -transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} >> hook_{{$hookSchema.Name | replace "-" "__dash__"}} >> publish_job_end_event |
| 307 | +transformation_{{$baseTaskSchema.Name | replace "-" "__dash__" | replace "." "__dot__"}} >> hook_{{$hookSchema.Name | replace "-" "__dash__"}} |
329 | 308 | {{- end -}} |
330 | 309 | {{- end }} |
331 | 310 |
|
|
334 | 313 | {{- $hookSchema := $t.Unit.Info }} |
335 | 314 | {{- range $_, $depend := $t.DependsOn }} |
336 | 315 | {{- $dependHookSchema := $depend.Unit.Info }} |
337 | | -hook_{{$dependHookSchema.Name | replace "-" "__dash__"}} >> hook_{{$hookSchema.Name | replace "-" "__dash__"}} >> publish_job_end_event |
| 316 | +hook_{{$dependHookSchema.Name | replace "-" "__dash__"}} >> hook_{{$hookSchema.Name | replace "-" "__dash__"}} |
338 | 317 | {{- end }} |
339 | 318 | {{- end }} |
340 | 319 |
|
|
349 | 328 | {{- $fhookSchema := $ftask.Unit.Info }} |
350 | 329 | {{- if eq $fhookSchema.HookType $.HookTypeFail }} hook_{{$fhookSchema.Name | replace "-" "__dash__"}}, {{- end -}} |
351 | 330 | {{- end -}} |
352 | | -] >> publish_job_end_event |
| 331 | +] |
353 | 332 |
|
354 | 333 | {{- end -}} |
355 | 334 |
|
|
0 commit comments