Skip to content

Commit 25b4ace

Browse files
author
geosolutions
committed
- Make processbot and servicebot more resilient to errors
1 parent 24745c6 commit 25b4ace

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/wpsremote/processbot.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,20 @@ def SpawnProcess(self):
164164
invoked_process = subprocess.Popen(args=cmd.split(), cwd=self._executable_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)
165165
logger.info("process " + self.service + " created with PId " + str(invoked_process.pid) + " and command line: " + cmd)
166166

167-
#read the resource file
168-
rc = resource_cleaner.Resource.create_from_file(self._uniqueExeId, os.getpid())
169-
#add the pid of the computational job to the resource file
170-
rc.set_from_processbot( os.getpid(), [ invoked_process.pid ] ) #todo: check if cmds contains ","!!! --> pickle?
171-
rc.write()
167+
try:
168+
#read the resource file
169+
rc = resource_cleaner.Resource.create_from_file(self._uniqueExeId, os.getpid())
170+
#add the pid of the computational job to the resource file
171+
rc.set_from_processbot( os.getpid(), [ invoked_process.pid ] ) #todo: check if cmds contains ","!!! --> pickle?
172+
rc.write()
173+
except Exception as ex:
174+
logging.exception( "Process "+str(self._uniqueExeId)+" Exception: "+str(traceback.format_exc(sys.exc_info())))
175+
error_message = "process failure\n" + str(ex)
176+
self.send_error_message( error_message )
177+
#self.bus.disconnect()
178+
logger.info( "after send job-error message to WPS")
179+
thread.interrupt_main()
180+
os._exit(return_code)
172181

173182
#go to process output synchronuosly
174183
self.process_output_parser( invoked_process )

src/wpsremote/servicebot.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ def handle_execute(self, execute_message):
149149
logger.debug("save parameters file for executing process " + self.service+ " in " + param_filepath)
150150

151151
#create the Resource Cleaner file containing the process info. The "invoked_process.pid" will be set by the spawned process itself
152-
153-
r = resource_cleaner.Resource()
154-
#create a resource...
155-
r.set_from_servicebot(execute_message.UniqueId(), self._output_dir / execute_message.UniqueId())
156-
#... and save to file
157-
r.write()
152+
try:
153+
r = resource_cleaner.Resource()
154+
#create a resource...
155+
r.set_from_servicebot(execute_message.UniqueId(), self._output_dir / execute_message.UniqueId())
156+
#... and save to file
157+
logger.info("Start the resource cleaner!")
158+
r.write()
159+
except Exception as ex:
160+
logger.exception("Resource Cleaner initialization error")
158161

159162
#invoke the process bot (aka request handler) asynchronously
160163
cmd = 'python wpsagent.py -r ' + self._remote_config_filepath + ' -s ' + self._service_config_file + ' -p ' + param_filepath + ' process'
@@ -198,8 +201,8 @@ def handle_getloadavg(self, getloadavg_message):
198201
outputs
199202
)
200203
)
201-
except Exception, err:
202-
print traceback.format_exc()
204+
except Exception as ex:
205+
logger.exception("Load Average initialization error")
203206

204207
#def output_parser(self, invoked_process):
205208
# #silently wait the end of the computaion

0 commit comments

Comments
 (0)