|
17 | 17 | AIRFLOW_VAR_MINIO_ENDPOINT, |
18 | 18 | AIRFLOW_VAR_MINIO_SECRET_KEY, |
19 | 19 | AIRFLOW_VAR_WASB_CONNECTION_STRING, |
20 | | - TEMP_TABLE_CLEANUP_DELAY, |
21 | 20 | storage_type, |
22 | 21 | ) |
23 | 22 |
|
@@ -217,74 +216,6 @@ def update_job_status_on_failure(context): |
217 | 216 | logging.error(f"Failed to update job status on skipped task: {str(e)}") |
218 | 217 |
|
219 | 218 |
|
220 | | -def handle_failure_and_cleanup_temp_tables(context): |
221 | | - """ |
222 | | - Delete temporary tables when the DAG fails or times out. |
223 | | -
|
224 | | - This handles cleanup when failures happen outside the normal pipeline code, like |
225 | | - timeouts or external errors. Since the tables are already in the database even if |
226 | | - the DAG fails, we query mapping_scanreporttable to find all tables for this |
227 | | - scan_report_id, then delete the temp tables (temp_data_dictionary and |
228 | | - temp_field_values). |
229 | | -
|
230 | | - When a timeout occurs, the task that was running may still be creating temporary tables in the background. |
231 | | - This function waits TEMP_TABLE_CLEANUP_DELAY seconds first so any in-flight table creation can finish, |
232 | | - then runs a single cleanup pass. Cleanup is not urgent, so waiting once is simpler than cleaning twice. |
233 | | -
|
234 | | -
|
235 | | - Args: |
236 | | - context: Airflow execution context containing task_instance, dag, dag_run, etc. |
237 | | - """ |
238 | | - try: |
239 | | - dag_run = context["dag_run"] |
240 | | - dag = context.get("dag") |
241 | | - dag_run_conf = dag_run.conf or {} |
242 | | - scan_report_id = dag_run_conf.get("scan_report_id") |
243 | | - |
244 | | - if not scan_report_id: |
245 | | - logging.warning( |
246 | | - "No scan_report_id found in DAG run configuration, skipping temp table cleanup" |
247 | | - ) |
248 | | - return |
249 | | - |
250 | | - # Update job status to FAILED for scan_report_processing DAG |
251 | | - if dag and dag.dag_id == "scan_report_processing": |
252 | | - try: |
253 | | - update_job_status( |
254 | | - stage=JobStageType.UPLOAD_SCAN_REPORT, |
255 | | - status=StageStatusType.FAILED, |
256 | | - scan_report=scan_report_id, |
257 | | - details="Scan report processing DAG timed out or failed.", |
258 | | - ) |
259 | | - logging.info( |
260 | | - "Updated job status to FAILED for scan_report_id=%s", |
261 | | - scan_report_id, |
262 | | - ) |
263 | | - except Exception as e: |
264 | | - logging.error("Failed to update job status on failure: %s", str(e)) |
265 | | - |
266 | | - # Wait so a timed-out task can finish creating tables, then delete the temporary tables |
267 | | - delay = TEMP_TABLE_CLEANUP_DELAY |
268 | | - time.sleep(delay) |
269 | | - |
270 | | - # I did this to avoid circular import |
271 | | - from libs.SR_processing.db_services import cleanup_temp_tables_for_scan_report |
272 | | - |
273 | | - table_pairs = cleanup_temp_tables_for_scan_report(scan_report_id) |
274 | | - if table_pairs: |
275 | | - logging.info( |
276 | | - "Deleted temp tables for scan_report_id=%s (n=%d)", |
277 | | - scan_report_id, |
278 | | - len(table_pairs), |
279 | | - ) |
280 | | - logging.info( |
281 | | - "Completed temp table cleanup for scan_report_id=%s", scan_report_id |
282 | | - ) |
283 | | - |
284 | | - except Exception as e: |
285 | | - logging.error("Failed to delete temporary tables on failure: %s", str(e)) |
286 | | - |
287 | | - |
288 | 219 | def create_task(task_id, python_callable, dag, provide_context=True): |
289 | 220 | """Create a task in the DAG""" |
290 | 221 | return PythonOperator( |
|
0 commit comments