| Dependency | Reason |
|---|---|
| Task Instance State | Task is in the 'success' state which is not a valid state for execution. The task must be cleared in order to be run. |
| Dagrun Running | Task instance's dagrun was not in the 'running' state but in the state 'success'. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | def getRiskRegisterData(**context):
ti = context.get("ti")
token = ti.xcom_pull(key="token")
response = requests.get(
url=f"{dRoW_api_end_url}/api/module/document-export/airflow/workflow/68f72cb8ee99729ef014ca38?export_type=0",
headers={
"x-access-token": f"Bearer {token}",
"ICWPxAccessKey": "5WSD21ICWP_[1AG:4UdI){n=b~"
}
)
risk_register_data = response.json()
print(f"check rr data: {risk_register_data}")
# thresholds: 3 months ≈ 90 days, 6 months ≈ 180 days
THRESHOLD_3M = 90
THRESHOLD_6M = 180
today = datetime.now(timezone.utc).date()
kpi9_count = 0 # Open records with elapsed_days > 90
kpi10_count = 0 # Open records with elapsed_days > 180
for item in risk_register_data:
rec = item.get("data", {}) or {}
status = rec.get("Status")
if status != "Open":
continue # only consider open records
ew_str = rec.get("Date of Early Warning")
if not ew_str:
continue # cannot compute elapsed time
try:
ew_date = parse_iso_date(ew_str).date()
except ValueError:
print(f"Unable to parse Date of Early Warning: {ew_str}")
continue
elapsed_days = (today - ew_date).days
if elapsed_days > THRESHOLD_3M:
kpi9_count += 1
if elapsed_days > THRESHOLD_6M:
kpi10_count += 1
print(f"KPI 9 (Open > 3 months): {kpi9_count}")
print(f"KPI 10 (Open > 6 months): {kpi10_count}")
result = {
"kpi9_open_gt_3m": kpi9_count,
"kpi10_open_gt_6m": kpi10_count,
}
# If you want to use XCom:
# ti.xcom_push(key="RISK_REGISTER_KPIS", value=result)
return result
|
| Attribute | Value |
|---|---|
| dag_id | nd201905_kpi |
| duration | 3.290805 |
| end_date | 2025-12-12 15:05:20.047712+00:00 |
| execution_date | 2025-12-12T07:00:00+00:00 |
| executor_config | {} |
| generate_command | <function TaskInstance.generate_command at 0x7fb2f39d0320> |
| hostname | a7c46ba165e9 |
| is_premature | False |
| job_id | 1780 |
| key | ('nd201905_kpi', 'getRiskRegisterData', <Pendulum [2025-12-12T07:00:00+00:00]>, 2) |
| log | <Logger airflow.task (INFO)> |
| log_filepath | /usr/local/airflow/logs/nd201905_kpi/getRiskRegisterData/2025-12-12T07:00:00+00:00.log |
| log_url | http://localhost:8080/admin/airflow/log?execution_date=2025-12-12T07%3A00%3A00%2B00%3A00&task_id=getRiskRegisterData&dag_id=nd201905_kpi |
| logger | <Logger airflow.task (INFO)> |
| mark_success_url | http://localhost:8080/success?task_id=getRiskRegisterData&dag_id=nd201905_kpi&execution_date=2025-12-12T07%3A00%3A00%2B00%3A00&upstream=false&downstream=false |
| max_tries | 1 |
| metadata | MetaData(bind=None) |
| next_try_number | 2 |
| operator | PythonOperator |
| pid | 1884207 |
| pool | default_pool |
| prev_attempted_tries | 1 |
| previous_execution_date_success | 2025-12-12 04:06:53.031357+00:00 |
| previous_start_date_success | 2025-12-12 04:10:12.347652+00:00 |
| previous_ti | <TaskInstance: nd201905_kpi.getRiskRegisterData 2025-12-12 04:06:53.031357+00:00 [success]> |
| previous_ti_success | <TaskInstance: nd201905_kpi.getRiskRegisterData 2025-12-12 04:06:53.031357+00:00 [success]> |
| priority_weight | 2 |
| queue | default |
| queued_dttm | 2025-12-12 15:04:58.976555+00:00 |
| raw | False |
| run_as_user | None |
| start_date | 2025-12-12 15:05:16.756907+00:00 |
| state | success |
| task | <Task(PythonOperator): getRiskRegisterData> |
| task_id | getRiskRegisterData |
| test_mode | False |
| try_number | 2 |
| unixname | airflow |
| Attribute | Value |
|---|---|
| dag | <DAG: nd201905_kpi> |
| dag_id | nd201905_kpi |
| depends_on_past | False |
| deps | {<TIDep(Trigger Rule)>, <TIDep(Previous Dagrun State)>, <TIDep(Not In Retry Period)>} |
| do_xcom_push | True |
| downstream_list | [<Task(PythonOperator): writeKpiToPostgres>] |
| downstream_task_ids | {'writeKpiToPostgres'} |
| None | |
| email_on_failure | True |
| email_on_retry | True |
| end_date | None |
| execution_timeout | None |
| executor_config | {} |
| extra_links | [] |
| global_operator_extra_link_dict | {} |
| inlets | [] |
| lineage_data | None |
| log | <Logger airflow.task.operators (INFO)> |
| logger | <Logger airflow.task.operators (INFO)> |
| max_retry_delay | None |
| on_failure_callback | None |
| on_retry_callback | None |
| on_success_callback | None |
| op_args | [] |
| op_kwargs | {} |
| operator_extra_link_dict | {} |
| operator_extra_links | () |
| outlets | [] |
| owner | airflow |
| params | {} |
| pool | default_pool |
| priority_weight | 1 |
| priority_weight_total | 2 |
| provide_context | True |
| queue | default |
| resources | None |
| retries | 1 |
| retry_delay | 0:05:00 |
| retry_exponential_backoff | False |
| run_as_user | None |
| schedule_interval | 0 7,15 * * * |
| shallow_copy_attrs | ('python_callable', 'op_kwargs') |
| sla | None |
| start_date | 2023-01-17T00:00:00+00:00 |
| subdag | None |
| task_concurrency | None |
| task_id | getRiskRegisterData |
| task_type | PythonOperator |
| template_ext | [] |
| template_fields | ('templates_dict', 'op_args', 'op_kwargs') |
| templates_dict | None |
| trigger_rule | all_success |
| ui_color | #ffefeb |
| ui_fgcolor | #000 |
| upstream_list | [<Task(PythonOperator): getContractData>] |
| upstream_task_ids | {'getContractData'} |
| wait_for_downstream | False |
| weight_rule | downstream |