Skip to content

Commit

Permalink
Handle JVM startup failures
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Sep 13, 2024
1 parent 2062927 commit 71d702a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/report_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ def __init__(self, logger):

def initialize(self):
if self.initialized == True:
return
return True

# Start JVM
libdir = os.path.join(os.path.dirname(__file__), 'libs')
classpath = glob.glob(os.path.join(libdir, '*.jar'))
classpath.append(libdir)
jpype.startJVM("-DJava.awt.headless=true", classpath=classpath)
try:
jpype.startJVM("-DJava.awt.headless=true", classpath=classpath)
except Exception as e:
self.logger.error("Failed to start JVM: %s" % str(e))
return False
self.DriverManager = jpype.JPackage('java').sql.DriverManager
self.ArrayList = jpype.JPackage('java').util.ArrayList
self.SimpleJasperReportsContext = jpype.JPackage('net').sf.jasperreports.engine.SimpleJasperReportsContext
Expand Down Expand Up @@ -118,6 +122,7 @@ def initialize(self):
self.pgservices[section] = dict(config.items(section))

self.initialized = True
return True

def resolve_datasource(self, datasource, report_filename):
""" Return a DB connection for a datasource name.
Expand Down Expand Up @@ -154,7 +159,9 @@ def compile_report(self, report_filename, fill_params, tmpdir, resources, permit
:param permitted_resources list: List of permitted resources
:param compile_subreport bool: Whether a subreport is being compiled
"""
self.initialize()
if not self.initialize():
return None

self.logger.info("Processing report %s" % report_filename)
reportdir_idx = len(os.path.abspath(self.report_dir)) + 1
# Copy to temp dir
Expand Down

0 comments on commit 71d702a

Please sign in to comment.