Skip to content

Commit

Permalink
- Make processbot and servicebot more resilient to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
geosolutions committed Jun 26, 2017
1 parent 24745c6 commit 25b4ace
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
19 changes: 14 additions & 5 deletions src/wpsremote/processbot.py
Expand Up @@ -164,11 +164,20 @@ def SpawnProcess(self):
invoked_process = subprocess.Popen(args=cmd.split(), cwd=self._executable_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)
logger.info("process " + self.service + " created with PId " + str(invoked_process.pid) + " and command line: " + cmd)

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

#go to process output synchronuosly
self.process_output_parser( invoked_process )
Expand Down
19 changes: 11 additions & 8 deletions src/wpsremote/servicebot.py
Expand Up @@ -149,12 +149,15 @@ def handle_execute(self, execute_message):
logger.debug("save parameters file for executing process " + self.service+ " in " + param_filepath)

#create the Resource Cleaner file containing the process info. The "invoked_process.pid" will be set by the spawned process itself

r = resource_cleaner.Resource()
#create a resource...
r.set_from_servicebot(execute_message.UniqueId(), self._output_dir / execute_message.UniqueId())
#... and save to file
r.write()
try:
r = resource_cleaner.Resource()
#create a resource...
r.set_from_servicebot(execute_message.UniqueId(), self._output_dir / execute_message.UniqueId())
#... and save to file
logger.info("Start the resource cleaner!")
r.write()
except Exception as ex:
logger.exception("Resource Cleaner initialization error")

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

#def output_parser(self, invoked_process):
# #silently wait the end of the computaion
Expand Down

0 comments on commit 25b4ace

Please sign in to comment.