def __init__(self, job_list): # Start by making a copy of job_list as we may modify it below job_list = job_list[:] while True: try: # Construct a solver with the job list as passed by the caller. # This will do a little bit of validation and might raise # DepdendencyDuplicateError if there are any duplicates at this # stage. # # There's a single case that is handled here though, if both # jobs are identical this problem is silently fixed. This # should not happen in normal circumstances but is non the less # harmless (as long as both jobs are perfectly identical) # # Since this problem can happen any number of times (many # duplicates) this is performed in a loop. The loop breaks when # we cannot solve the problem _OR_ when no error occurs. DependencySolver(job_list) except DependencyDuplicateError as exc: # If both jobs are identical then silently fix the problem by # removing one of the jobs (here the second one we've seen but # it's not relevant as they are possibly identical) and try # again if exc.job == exc.duplicate_job: job_list.remove(exc.duplicate_job) continue else: # If the jobs differ report this back to the caller raise else: # If there are no problems then break the loop break self._job_list = job_list self._job_state_map = { job.name: JobState(job) for job in self._job_list } self._desired_job_list = [] self._run_list = [] self._resource_map = {} # Temporary directory used as 'scratch space' for running jobs. Removed # entirely when session is terminated. Internally this is exposed as # $CHECKBOX_DATA to script environment. self._session_dir = None # Directory used to store jobs IO logs. self._jobs_io_log_dir = None
def __init__(self, job_list): """ Initialize a new SessionState with a given list of jobs. The jobs are all of the jobs that the session knows about. """ # Start by making a copy of job_list as we may modify it below job_list = job_list[:] while True: try: # Construct a solver with the job list as passed by the caller. # This will do a little bit of validation and might raise # DepdendencyDuplicateError if there are any duplicates at this # stage. # # There's a single case that is handled here though, if both # jobs are identical this problem is silently fixed. This # should not happen in normal circumstances but is non the less # harmless (as long as both jobs are perfectly identical) # # Since this problem can happen any number of times (many # duplicates) this is performed in a loop. The loop breaks when # we cannot solve the problem _OR_ when no error occurs. DependencySolver(job_list) except DependencyDuplicateError as exc: # If both jobs are identical then silently fix the problem by # removing one of the jobs (here the second one we've seen but # it's not relevant as they are possibly identical) and try # again if exc.job == exc.duplicate_job: job_list.remove(exc.duplicate_job) continue else: # If the jobs differ report this back to the caller raise else: # If there are no problems then break the loop break self._job_list = job_list self._job_state_map = {job.name: JobState(job) for job in self._job_list} self._desired_job_list = [] self._run_list = [] self._resource_map = {} self._metadata = SessionMetaData() super(SessionState, self).__init__()