Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-20 07:58:59

0001 import os.path
0002 
0003 from pandaharvester.harvestercore import core_utils
0004 from pandaharvester.harvestercore.plugin_base import PluginBase
0005 from pandaharvester.harvestercore.work_spec import WorkSpec
0006 
0007 # logger
0008 baseLogger = core_utils.setup_logger("dummy_monitor")
0009 
0010 
0011 # dummy monitor
0012 class DummyMonitor(PluginBase):
0013     # constructor
0014     def __init__(self, **kwarg):
0015         PluginBase.__init__(self, **kwarg)
0016 
0017     # check workers
0018     def check_workers(self, workspec_list):
0019         """Check status of workers. This method takes a list of WorkSpecs as input argument
0020         and returns a list of worker's statuses.
0021         Nth element if the return list corresponds to the status of Nth WorkSpec in the given list. Worker's
0022         status is one of WorkSpec.ST_finished, WorkSpec.ST_failed, WorkSpec.ST_cancelled, WorkSpec.ST_running,
0023         WorkSpec.ST_submitted. nativeExitCode and nativeStatus of WorkSpec can be arbitrary strings to help
0024         understanding behaviour of the resource and/or batch scheduler.
0025 
0026         :param workspec_list: a list of work specs instances
0027         :return: A tuple of return code (True for success, False otherwise) and a list of worker's statuses.
0028         :rtype: (bool, [string,])
0029         """
0030         retList = []
0031         for workSpec in workspec_list:
0032             # make logger
0033             tmpLog = self.make_logger(baseLogger, f"workerID={workSpec.workerID}", method_name="check_workers")
0034             dummyFilePath = os.path.join(workSpec.get_access_point(), "status.txt")
0035             tmpLog.debug(f"look for {dummyFilePath}")
0036             newStatus = WorkSpec.ST_finished
0037             try:
0038                 with open(dummyFilePath) as dummyFile:
0039                     newStatus = dummyFile.readline()
0040                     newStatus = newStatus.strip()
0041                     if newStatus == "finished":
0042                         workSpec.nativeExitCode = 0
0043                         workSpec.nativeStatus = "done"
0044             except Exception:
0045                 pass
0046             tmpLog.debug(f"newStatus={newStatus}")
0047             retList.append((newStatus, "dialog_message"))
0048         return True, retList