[ 
https://issues.apache.org/jira/browse/BEAM-8523?focusedWorklogId=350117&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-350117
 ]

ASF GitHub Bot logged work on BEAM-8523:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Nov/19 00:31
            Start Date: 27/Nov/19 00:31
    Worklog Time Spent: 10m 
      Work Description: chadrik commented on pull request #9959: [BEAM-8523] 
JobAPI: Give access to timestamped state change history
URL: https://github.com/apache/beam/pull/9959#discussion_r351045675
 
 

 ##########
 File path: sdks/python/apache_beam/runners/portability/abstract_job_service.py
 ##########
 @@ -115,13 +127,43 @@ def __init__(self, job_id, job_name, pipeline, options):
     self._job_name = job_name
     self._pipeline_proto = pipeline
     self._pipeline_options = options
+    self._state_history = [(beam_job_api_pb2.JobState.STOPPED, time.time())]
 
   def _to_implement(self):
     raise NotImplementedError(self)
 
   prepare = run = cancel = _to_implement
   artifact_staging_endpoint = _to_implement
-  get_state = get_state_stream = get_message_stream = _to_implement
+  get_state_stream = get_message_stream = _to_implement
+
+  @property
+  def state(self):
+    """Get the latest state enum."""
+    return self.get_state()[0]
+
+  def get_state(self):
+    """Get a tuple of the latest state and its timestamp."""
+    # this is safe: initial state is set in __init__
+    return self._state_history[-1]
+
+  def set_state(self, new_state):
+    """Set the latest state as an int enum and update the state history.
+
+    :param new_state: int
+      latest state enum
+    :return: float or None
+      the new timestamp if the state has not changed, else None
+    """
+    if new_state != self._state_history[-1][0]:
+      timestamp = time.time()
 
 Review comment:
   yeah, good suggestion. 
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 350117)
    Time Spent: 3h 40m  (was: 3.5h)

> Add useful timestamp to job servicer GetJobs
> --------------------------------------------
>
>                 Key: BEAM-8523
>                 URL: https://issues.apache.org/jira/browse/BEAM-8523
>             Project: Beam
>          Issue Type: New Feature
>          Components: beam-model
>            Reporter: Chad Dombrova
>            Assignee: Chad Dombrova
>            Priority: Major
>          Time Spent: 3h 40m
>  Remaining Estimate: 0h
>
> As a user querying jobs with JobService.GetJobs, it would be useful if the 
> JobInfo result contained timestamps indicating various state changes that may 
> have been missed by a client.   Useful timestamps include:
>  
>  * submitted (prepared to the job service)
>  * started (executor enters the RUNNING state)
>  * completed (executor enters a terminal state)
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to