def parse( self, strx ): if strx == "now": strx = now().strftime("%Y%m%d%H%M%S") n = len(strx) if n == 4 or n == 6 or n == 8 or n == 10 or n == 12 or n == 14: self.strvalue = strx + ct.YYYYMMDDHHmmss[n:] else: raise InvalidCycleTimeError, 'ERROR: Illegal cycle time (YYYY[MM[DD[HH[mm[ss]]]]]): ' + strx #self.strvalue_Y2H = self.strvalue[0:10] self.year = self.strvalue[ 0:4 ] self.month = self.strvalue[ 4:6 ] self.day = self.strvalue[ 6:8 ] self.hour = self.strvalue[ 8:10] self.minute = self.strvalue[10:12] self.seconds = self.strvalue[12:14] self.HHmmss = self.strvalue[ 8:14 ] self.DDHHmmss = self.strvalue[ 6:14 ] self.MMDDHHmmss = self.strvalue[ 4:14 ] # convert to datetime as a validity check try: self.dtvalue = datetime.datetime( int(self.year), int(self.month), int(self.day), int(self.hour), int(self.minute), int(self.seconds)) except ValueError,x: # returns sensible messages: "minute must be in 0..59" raise InvalidCycleTimeError( x.__str__() + ': ' + self.get_formatted() )
def dump( self, tasks=None, wireless=None ): """Dump suite states to disk. Return state file basename on success.""" if wireless is None: wireless = self.wireless base_name = self.BASE_NAME + "." + now().strftime("%Y%m%dT%H%M%S.%fZ") file_name = os.path.join(self.dir_name, base_name) # write the state dump file, retrying several times in case of: # (a) log rolling error when cylc-run contents have been deleted, # (b) "[Errno 9] bad file descriptor" at BoM - see github #926. max_attempts = 5 n_attempt = 1 while True: try: handle = open(file_name, "wb") handle.write('run mode : %s\n' % self.run_mode) handle.write('time : %s\n' % now().strftime("%Y:%m:%d:%H:%M:%S")) handle.write(self.cts_str) if wireless is not None: wireless.dump(handle) handle.write('Begin task states\n') if tasks is None and self.pool is not None: tasks = self.pool.get_tasks() if tasks is not None: for itask in sorted(tasks, key=lambda t: t.id): itask.dump_class_vars( handle ) itask.dump_state( handle ) # To generate "OSError [Errno 9] bad file descriptor", # close the file with os.close() before calling fsync(): ## os.close( handle.fileno() ) os.fsync( handle.fileno() ) handle.close() except (IOError, OSError) as exc: if not exc.filename: exc.filename = file_name self.log.warning( 'State dumping failed, #' + str(n_attempt) + ' ' + str(exc) ) if n_attempt >= max_attempts: raise exc n_attempt += 1 try: handle.close() except: pass time.sleep(0.2) else: break # Point "state" symbolic link to new dated state dump try: os.unlink(self.file_name) except OSError as x: if x.errno != errno.ENOENT: raise os.symlink(base_name, self.file_name) self.arch_files.append(file_name) # Remove state dump older than archive length while len(self.arch_files) > self.arch_len: try: os.unlink(self.arch_files.pop(0)) except OSError as x: if x.errno != errno.ENOENT: raise return base_name
def update( self, tasks, oldest, newest, newest_nonrunahead, paused, will_pause_at, stopping, will_stop_at, runahead, ns_defn_order ): task_name_list = [] task_summary = {} global_summary = {} family_summary = {} task_states = {} for task in tasks: task_summary[ task.id ] = task.get_state_summary() name, ctime = task.id.split(TaskID.DELIM) task_states.setdefault(ctime, {}) task_states[ctime][name] = task_summary[task.id]['state'] task_name_list.append(name) task_name_list = list(set(task_name_list)) fam_states = {} all_states = [] for ctime, c_task_states in task_states.items(): # For each cycle time, construct a family state tree # based on the first-parent single-inheritance tree c_fam_task_states = {} c_task_states = task_states.get(ctime, {}) for key, parent_list in self.config.get_first_parent_ancestors().items(): state = c_task_states.get(key) if state is None: continue all_states.append( state ) for parent in parent_list: if parent == key: continue c_fam_task_states.setdefault(parent, []) c_fam_task_states[parent].append(state) for fam, child_states in c_fam_task_states.items(): f_id = fam + TaskID.DELIM + ctime state = extract_group_state(child_states) if state is None: continue try: famcfg = self.config.cfg['runtime'][fam] except KeyError: famcfg = {} description = famcfg.get('description') title = famcfg.get('title') family_summary[f_id] = {'name': fam, 'description': description, 'title': title, 'label': ctime, 'state': state} all_states.sort() global_summary[ 'start time' ] = self.start_time global_summary[ 'oldest cycle time' ] = oldest global_summary[ 'newest cycle time' ] = newest global_summary[ 'newest non-runahead cycle time' ] = newest_nonrunahead global_summary[ 'last_updated' ] = now() global_summary[ 'run_mode' ] = self.run_mode global_summary[ 'paused' ] = paused global_summary[ 'stopping' ] = stopping global_summary[ 'will_pause_at' ] = will_pause_at global_summary[ 'will_stop_at' ] = will_stop_at global_summary[ 'runahead limit' ] = runahead global_summary[ 'states' ] = all_states global_summary[ 'namespace definition order' ] = ns_defn_order self._summary_update_time = time.time() # replace the originals self.task_name_list = task_name_list self.task_summary = task_summary self.global_summary = global_summary self.family_summary = family_summary task_states = {}