tweak job runs
This commit is contained in:
parent
2b2a3f1cc0
commit
c210168d65
6 changed files with 94 additions and 12 deletions
|
|
@ -504,10 +504,11 @@ def _project_upcoming_job(
|
|||
"slug": job.source.slug,
|
||||
"job_id": job_id,
|
||||
"next_run": (
|
||||
next_run.strftime("%Y-%m-%d %H:%M UTC")
|
||||
_humanize_future_time(reference_time, next_run)
|
||||
if next_run is not None
|
||||
else ("Running now" if running_execution is not None else "Not scheduled")
|
||||
),
|
||||
"next_run_at": next_run.isoformat() if next_run is not None else None,
|
||||
"schedule": " ".join(
|
||||
(
|
||||
str(job.cron_minute),
|
||||
|
|
@ -641,3 +642,22 @@ def _format_bytes(value: int) -> str:
|
|||
if value < 1024 * 1024 * 1024:
|
||||
return f"{value / (1024 * 1024):.1f} MB"
|
||||
return f"{value / (1024 * 1024 * 1024):.1f} GB"
|
||||
|
||||
|
||||
def _humanize_future_time(reference_time: datetime, target_time: datetime) -> str:
|
||||
delta_seconds = int(round((target_time - reference_time).total_seconds()))
|
||||
if delta_seconds <= 0:
|
||||
return "now"
|
||||
|
||||
units = (
|
||||
("day", 24 * 60 * 60),
|
||||
("hour", 60 * 60),
|
||||
("minute", 60),
|
||||
)
|
||||
for label, size in units:
|
||||
if delta_seconds >= size:
|
||||
count = max(1, round(delta_seconds / size))
|
||||
suffix = "" if count == 1 else "s"
|
||||
return f"in {count} {label}{suffix}"
|
||||
|
||||
return f"in {delta_seconds} seconds"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue