def db_info_by_age(self, use_status_time=False): """ Sort wikis in reverse order of last successful dump and return tuples of information for each wiki: * whether the dump failed, * the date of the run as found in dump dir string OR as determined by time of status file, if use_status_time is True, * age of status file if any, * wiki name Order is (DumpFailed, Age), and False < True: First, wikis whose latest dump was successful, most recent dump first Then, wikis whose latest dump failed, most recent dump first. Finally, wikis which have never been dumped. According to that sort, the last item of this list is, when applicable, the oldest failed dump attempt. If some error occurs checking a dump status, that dump is put last in the list (sort value is (True, maxsize) ) Note that we now sort this list by the date of the dump directory, not the last date that a dump file in that directory may have been touched. This allows us to rerun jobs to completion from older runs, for example an en pedia history urn that failed in the middle, without borking the index page links. """ available = [] today = int(TimeUtils.today()) for dbname in self.db_list: wiki = Wiki(self, dbname) age = sys.maxsize date = sys.maxsize last = wiki.latest_dump() status = '' if last: dump_status = StatusHtml.get_statusfile_path(wiki, last) try: if use_status_time: # only use the status file time, not the dir date date = today else: date = today - int(last) # tack on the file mtime so that if we have multiple wikis # dumped on the same day, they get ordered properly age = FileUtils.file_age(dump_status) status = FileUtils.read_file(dump_status) except Exception as ex: print("dump dir missing status file %s?" % dump_status) dump_failed = (status == '') or ('dump aborted' in status) available.append((dump_failed, date, age, dbname)) available = sorted(available) return available
def lock_age(self, lockfile=None): if lockfile is not None: return FileUtils.file_age(lockfile) return FileUtils.file_age(self.get_lock_file_path())