Skip to content

Commit 6265269

Browse files
authored
[HWORKS-1565] Make sure the program exits after completion (#275)
1 parent 67c8fa6 commit 6265269

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

utils/java/src/main/java/com/logicalclocks/utils/MainClass.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,22 @@ public static void main(String[] args) throws Exception {
115115
}
116116
LOGGER.info("Hsfs utils write options: {}", writeOptions);
117117

118+
boolean success = false;
118119
try {
119120
if (op.equals("offline_fg_materialization") || op.equals("offline_fg_backfill")) {
120121
SparkEngine.getInstance().streamToHudiTable(streamFeatureGroup, writeOptions);
121122
}
123+
success = true;
122124
} finally {
123125
LOGGER.info("Closing spark session...");
124-
SparkEngine.getInstance().closeSparkSession();
126+
try {
127+
SparkEngine.getInstance().closeSparkSession();
128+
} catch (Exception e) {
129+
LOGGER.error("Error closing spark session", e);
130+
}
131+
if (!success) {
132+
System.exit(1);
133+
}
125134
}
126135
System.exit(0);
127136
}

utils/python/hsfs_utils.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
import os
45
import argparse
56
import json
@@ -285,6 +286,7 @@ def parse_isoformat_date(da: str) -> datetime:
285286
args = parser.parse_args()
286287
job_conf = read_job_conf(args.path)
287288

289+
success = False
288290
try:
289291
if args.op == "insert_fg":
290292
insert_fg(spark, job_conf)
@@ -300,6 +302,16 @@ def parse_isoformat_date(da: str) -> datetime:
300302
import_fg(job_conf)
301303
elif args.op == "run_feature_monitoring":
302304
run_feature_monitoring(job_conf)
305+
306+
success = True
303307
finally:
304308
if spark is not None:
305-
spark.stop()
309+
try:
310+
spark.stop()
311+
except Exception as e:
312+
print(f"Error stopping spark session: {e}")
313+
if not success:
314+
sys.exit(1)
315+
316+
sys.exit(0)
317+

0 commit comments

Comments
 (0)