Skip to content

Commit

Permalink
Merge pull request #1004 from Yelp/u/kkasp/TRON-2237-timedeltas-cant-…
Browse files Browse the repository at this point in the history
…json

Use total_seconds for timedeltas. Log job and jobrun names/runnums on serialization
  • Loading branch information
KaspariK authored Oct 31, 2024
2 parents c6dc990 + dfcb916 commit 5debd34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tron/core/actionrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ def state_data(self):
@staticmethod
def to_json(state_data: dict) -> Optional[str]:
"""Serialize the ActionRun instance to a JSON string."""

action_runner = state_data.get("action_runner")
if action_runner is None:
action_runner_json = NoActionRunnerFactory.to_json()
Expand All @@ -759,7 +760,9 @@ def to_json(state_data: dict) -> Optional[str]:
"exit_status": state_data["exit_status"],
"attempts": [ActionRunAttempt.to_json(attempt) for attempt in state_data["attempts"]],
"retries_remaining": state_data["retries_remaining"],
"retries_delay": state_data["retries_delay"],
"retries_delay": state_data["retries_delay"].total_seconds()
if state_data["retries_delay"] is not None
else None,
"action_runner": action_runner_json,
"executor": state_data["executor"],
"trigger_downstreams": state_data["trigger_downstreams"],
Expand Down
2 changes: 2 additions & 0 deletions tron/serialize/runstate/dynamodb_state_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ def get_type_from_key(self, key: str) -> str:
def _serialize_item(self, key: Literal[runstate.JOB_STATE, runstate.JOB_RUN_STATE], state: Dict[str, Any]) -> Optional[str]: # type: ignore
try:
if key == runstate.JOB_STATE:
log.info(f"Serializing Job: {state.get('job_name')}")
return Job.to_json(state)
elif key == runstate.JOB_RUN_STATE:
log.info(f"Serializing JobRun: {state.get('job_name')}.{state.get('run_num')}")
return JobRun.to_json(state)
else:
raise ValueError(f"Unknown type: key {key}")
Expand Down

0 comments on commit 5debd34

Please sign in to comment.