def format(self, **kwargs): tb = " " nl = "\n" fin = self.finish if self.finish else DateUtil.now() duration = round( (fin - self.start).total_seconds()) if self.start else 0 updated_text = "Unknown" if self.last_updated: secs_ago = int( (DateUtil.now() - self.last_updated).total_seconds()) if secs_ago > 2: updated_text = second_formatter(secs_ago) + " ago" else: updated_text = "Just now" updated_text += f" ({self.last_updated.replace(microsecond=0).isoformat()})" return f"""\ WID: {self.wid} EngId: {self.engine_wid} Name: {self.name} Engine: {self.engine} Task Dir: {self.outdir} Exec Dir: {self.execution_dir} Status: {self.status} Duration: {second_formatter(duration)} Start: {self.start.isoformat() if self.start else 'N/A'} Finish: {self.finish.isoformat() if self.finish else "N/A"} Updated: {updated_text} Jobs: {nl.join(j.format(tb, **kwargs) for j in sorted(self.jobs, key=lambda j: j.start or DateUtil.now()))} {("Outputs:" + "".join(nl + tb + o.format() for o in self.outputs) if self.outputs else '')} {("Error: " + self.error) if self.error else ''} """.strip()
def test_day(self): secs = 86400 self.assertEqual("1d:00h:00m:00s", second_formatter(secs))
def test_under_day_3(self): secs = 86399 self.assertEqual("23h:59m:59s", second_formatter(secs))
def test_under_day_2(self): secs = 3660 self.assertEqual("1h:01m:00s", second_formatter(secs))
def test_under_hour_4(self): secs = 3599 self.assertEqual("59m:59s", second_formatter(secs))
def test_under_hour_3(self): secs = 609 self.assertEqual("10m:09s", second_formatter(secs))
def test_under_hour_2(self): secs = 70 self.assertEqual("1m:10s", second_formatter(secs))
def test_under_hour_1(self): secs = 60 self.assertEqual("1m:00s", second_formatter(secs))
def test_under_minute_4(self): secs = 59 self.assertEqual("59s", second_formatter(secs))
def test_under_minute_3(self): secs = 22 self.assertEqual("22s", second_formatter(secs))
def test_under_minute_2(self): secs = 8 self.assertEqual("8s", second_formatter(secs))
def test_under_minute_1(self): secs = 0 self.assertEqual("0s", second_formatter(secs))
def format(self, **kwargs): tb = " " nl = "\n" start, finish = None, DateUtil.now() last_updated = None if self.runs: start_times = [s.start for s in self.runs if s.start] finish_times = [s.finish for s in self.runs if s.finish] last_updated_times = [ s.last_updated for s in self.runs if s.last_updated ] if start_times: start = min(start_times) if finish_times and len(finish_times) == len(self.runs): finish = max(finish_times) if last_updated_times: last_updated = max(last_updated_times) fin = finish or DateUtil.now() duration = round((fin - start).total_seconds()) if start else 0 updated_text = "Unknown" if last_updated: secs_ago = int((DateUtil.now() - last_updated).total_seconds()) if secs_ago > 2: updated_text = second_formatter(secs_ago) + " ago" else: updated_text = "Just now" updated_text += f" ({last_updated.replace(microsecond=0).isoformat()})" engine_ids, rstatuses, errors = "", "", [] if self.error: errors.append(f"GLOBAL: {self.error}") if self.runs: engine_ids = ", ".join(r.engine_id for r in self.runs if r.engine_id) errors.extend(r.error for r in self.runs if r.error) rstatuses = ", ".join( str(r.status.to_string()) for r in self.runs if r.status) statuses = self.status.to_string() if self.status else rstatuses ers = "\n".join(errors) return f"""\ SID: {self.id_} EngId: {engine_ids} Engine: {self.engine_type} Task Dir: {self.output_dir} Exec Dir: {self.execution_dir} Name: {self.get_names() or 'N/A'} Status: {statuses} Duration: {second_formatter(duration)} Start: {start.isoformat() if start else 'N/A'} Finish: {finish.isoformat() if finish else "N/A"} Updated: {updated_text} Jobs: {nl.join(j.format(tb, **kwargs) for j in sorted(self.runs, key=lambda j: j.start or DateUtil.now()))} {("Error: " + ers) if ers else ''} """.strip()