Skip to content

Commit

Permalink
chore: rename various timestamp fields to timestamp_ns
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodearnest committed Jan 6, 2023
1 parent 8d3d83f commit 1647d88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
18 changes: 9 additions & 9 deletions jobrunner/executors/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,27 @@ def get_status(self, job, timeout=15):

if container is None: # container doesn't exist
# timestamp file presence means we have finished preparing
timestamp = volume_api.read_timestamp(job, TIMESTAMP_REFERENCE_FILE, 10)
timestamp_ns = volume_api.read_timestamp(job, TIMESTAMP_REFERENCE_FILE, 10)
# TODO: maybe log the case where the volume exists, but the
# timestamp file does not? It's not a problems as the loop should
# re-prepare it anyway.
if timestamp is None:
if timestamp_ns is None:
# we are Jon Snow
return JobStatus(ExecutorState.UNKNOWN)
else:
# we've finish preparing
return JobStatus(ExecutorState.PREPARED, timestamp=timestamp)
return JobStatus(ExecutorState.PREPARED, timestamp_ns=timestamp_ns)

if container["State"]["Running"]:
timestamp = datestr_to_ns_timestamp(container["State"]["StartedAt"])
return JobStatus(ExecutorState.EXECUTING, timestamp=timestamp)
timestamp_ns = datestr_to_ns_timestamp(container["State"]["StartedAt"])
return JobStatus(ExecutorState.EXECUTING, timestamp_ns=timestamp_ns)
elif job.id in RESULTS:
return JobStatus(
ExecutorState.FINALIZED, timestamp=RESULTS[job.id].timestamp
ExecutorState.FINALIZED, timestamp_ns=RESULTS[job.id].timestamp_ns
)
else: # container present but not running, i.e. finished
timestamp = datestr_to_ns_timestamp(container["State"]["FinishedAt"])
return JobStatus(ExecutorState.EXECUTED, timestamp=timestamp)
timestamp_ns = datestr_to_ns_timestamp(container["State"]["FinishedAt"])
return JobStatus(ExecutorState.EXECUTED, timestamp_ns=timestamp_ns)

def get_results(self, job):
if job.id not in RESULTS:
Expand Down Expand Up @@ -319,7 +319,7 @@ def finalize_job(job):
exit_code=container_metadata["State"]["ExitCode"],
image_id=container_metadata["Image"],
message=message,
timestamp=time.time_ns(),
timestamp_ns=time.time_ns(),
action_version=labels.get("org.opencontainers.image.version", "unknown"),
action_revision=labels.get("org.opencontainers.image.revision", "unknown"),
action_created=labels.get("org.opencontainers.image.created", "unknown"),
Expand Down
6 changes: 4 additions & 2 deletions jobrunner/job_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class ExecutorState(Enum):
class JobStatus:
state: ExecutorState
message: Optional[str] = None
timestamp: int = None # timestamp this JobStatus occurred, in integer nanoseconds
timestamp_ns: int = (
None # timestamp this JobStatus occurred, in integer nanoseconds
)


@dataclass
Expand All @@ -61,7 +63,7 @@ class JobResults:
image_id: str
message: str = None
# timestamp these results were finalized, in integer nanoseconds
timestamp: int = None
timestamp_ns: int = None

# to be extracted from the image labels
action_version: str = "unknown"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_local_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_prepare_success(docker_cleanup, test_repo, tmp_work_dir, volume_api, fr
next_status = api.get_status(job)

assert next_status.state == ExecutorState.PREPARED
assert next_status.timestamp == expected_timestamp
assert next_status.timestamp_ns == expected_timestamp

assert volume_api.volume_exists(job)

Expand Down Expand Up @@ -341,9 +341,9 @@ def test_finalize_success(docker_cleanup, test_repo, tmp_work_dir, volume_api):

# check that timestamp is as expected
container = docker.container_inspect(local.container_name(job))
assert status.timestamp == datestr_to_ns_timestamp(container["State"]["FinishedAt"])

assert status.timestamp
assert status.timestamp_ns == datestr_to_ns_timestamp(
container["State"]["FinishedAt"]
)

status = api.finalize(job)
assert status.state == ExecutorState.FINALIZING
Expand Down

0 comments on commit 1647d88

Please sign in to comment.