Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
allowed_max_job_name_length=allowed_max_job_name_length,
state=(job.get("state") or "unknown"),
start_time=f"{str(start_time)} ({humanize.naturaltime(start_time)})",
dashboard_url=PaastaColors.grey(f"{dashboard_url}/#/jobs/{job_id}"),
)
)
if verbose and job_id in status.exceptions:
exceptions = status.exceptions[job_id]
root_exception = exceptions["root-exception"]
if root_exception is not None:
output.append(f" Exception: {root_exception}")
ts = exceptions["timestamp"]
if ts is not None:
exc_ts = datetime.fromtimestamp(int(ts) // 1000)
output.append(
f" {str(exc_ts)} ({humanize.naturaltime(exc_ts)})"
)
if verbose and len(status.pod_status) > 0:
output.append(f" Pods:")
rows: List[Union[str, Tuple[str, str, str]]] = [("Pod Name", "Host", "Phase")]
for pod in status.pod_status:
rows.append((pod["name"], pod["host"], pod["phase"]))
if pod["reason"] != "":
rows.append(PaastaColors.grey(f" {pod['reason']}: {pod['message']}"))
pods_table = format_table(rows)
output.extend([f" {line}" for line in pods_table])
return 0
start_time=f"{str(start_time)} ({humanize.naturaltime(start_time)})",
dashboard_url=PaastaColors.grey(f"{dashboard_url}/#/jobs/{job_id}"),
)
)
if verbose and job_id in status.exceptions:
exceptions = status.exceptions[job_id]
root_exception = exceptions["root-exception"]
if root_exception is not None:
output.append(f" Exception: {root_exception}")
ts = exceptions["timestamp"]
if ts is not None:
exc_ts = datetime_from_utc_to_local(
datetime.utcfromtimestamp(int(ts) // 1000)
)
output.append(
f" {str(exc_ts)} ({humanize.naturaltime(exc_ts)})"
)
return 0
)
for job in unique_jobs:
job_id = job["jid"]
if verbose:
fmt = """ {job_name: <{allowed_max_job_name_length}.{allowed_max_job_name_length}} {state: <11} {job_id} {start_time}
{dashboard_url}"""
else:
fmt = " {job_name: <{allowed_max_job_name_length}.{allowed_max_job_name_length}} {state: <11} {start_time}"
start_time = datetime.fromtimestamp(int(job["start-time"]) // 1000)
output.append(
fmt.format(
job_id=job_id,
job_name=get_flink_job_name(job),
allowed_max_job_name_length=allowed_max_job_name_length,
state=(job.get("state") or "unknown"),
start_time=f"{str(start_time)} ({humanize.naturaltime(start_time)})",
dashboard_url=PaastaColors.grey(f"{dashboard_url}/#/jobs/{job_id}"),
)
)
if verbose and job_id in status.exceptions:
exceptions = status.exceptions[job_id]
root_exception = exceptions["root-exception"]
if root_exception is not None:
output.append(f" Exception: {root_exception}")
ts = exceptions["timestamp"]
if ts is not None:
exc_ts = datetime.fromtimestamp(int(ts) // 1000)
output.append(
f" {str(exc_ts)} ({humanize.naturaltime(exc_ts)})"
)
if verbose and len(status.pod_status) > 0:
output.append(f" Pods:")
def test_naturaldelta_minimum_unit_explicit(minimum_unit, seconds, expected):
# Arrange
delta = dt.timedelta(seconds=seconds)
# Act / Assert
assert humanize.naturaldelta(delta, minimum_unit=minimum_unit) == expected
def nd_nomonths(d):
return humanize.naturaldelta(d, months=False)
def _report(self):
delta = self.end - self.start
timeString = humanize.time.naturaldelta(delta)
print("Finished in {} ({} seconds)".format(timeString, delta))
def _updateDisplay(self):
fileName = self._getFileNameDisplayString()
# TODO contentLength seems to slightly under-report how many bytes
# we have to download... hence the min functions
percentage = min(self.bytesWritten / self.contentLength, 1)
numerator = humanize.filesize.naturalsize(
min(self.bytesWritten, self.contentLength))
denominator = humanize.filesize.naturalsize(
self.contentLength)
displayString = "{} {:<6.2%} ({:>9} / {:<9})\r"
self.stream.write(displayString.format(
fileName, percentage, numerator, denominator))
self.stream.flush()
def test_naturalday(test_args, expected):
assert humanize.naturalday(*test_args) == expected
def test_naturaldate(test_input, expected):
assert humanize.naturaldate(test_input) == expected
def test_use_utc(self, h):
assert humanize.time._now == datetime.utcnow