Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktaubeneck committed Jul 10, 2024
1 parent 6af84f2 commit 5857e71
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
15 changes: 9 additions & 6 deletions server/app/query/view/[id]/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,22 @@ export function RunTimePill({
startTime: number | null;
endTime: number | null;
}) {
const [runTime, setRunTime] = useState<number>(0);
const [runTime, setRunTime] = useState<number | null>(null);
const runTimeStr = runTime ? secondsToTime(runTime) : "N/A";
const intervalId = useRef<ReturnType<typeof setTimeout> | null>(null);

useEffect(() => {
if (startTime !== null) {
if (intervalId.current !== null) {
// any time startTime or endTime change, we remove the old setInterval
// which runs the timer. if a new one is needed, it's created.
clearTimeout(intervalId.current);
}
if (startTime === null) {
setRunTime(null);
} else {
if (endTime !== null && startTime !== null) {
setRunTime(endTime - startTime);
} else {
if (intervalId.current !== null) {
clearTimeout(intervalId.current);
}

let newIntervalId = setInterval(() => {
setRunTime(Date.now() / 1000 - startTime);
}, 1000);
Expand Down
35 changes: 20 additions & 15 deletions sidecar/app/query/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,25 @@ def get_from_query_id(cls, query_id) -> Optional["Query"]:
if query:
return query
raise e
if query.status_file_path.exists():
with query.status_file_path.open("r") as f:
query.load_history_from_file()
if query.status == Status.UNKNOWN:
return None
return query

def load_history_from_file(self):
if self.status_file_path.exists():
self.logger.debug(
f"Loading query {self.query_id} status history "
f"from file {self.status_file_path}"
)
with self.status_file_path.open("r") as f:
for line in f:
status_str, timestamp = line.split(",")
query.add_status_event(
status=Status[status_str], timestamp=float(timestamp)
self._status_history.append(
StatusChangeEvent(
status=Status[status_str], timestamp=float(timestamp)
)
)
return query
return None

@property
def _last_status_event(self):
Expand All @@ -118,15 +128,10 @@ def status(self) -> Status:
def status(self, status: Status):
if self.status <= Status.COMPLETE:
now = time.time()
self.add_status_event(status, now)

def add_status_event(self, status: Status, timestamp: float):
self._status_history.append(
StatusChangeEvent(status=status, timestamp=timestamp)
)
with self.status_file_path.open("a") as f:
self.logger.debug(f"updating status: {status=}")
f.write(f"{status.name},{timestamp}\n")
self._status_history.append(StatusChangeEvent(status=status, timestamp=now))
with self.status_file_path.open("a") as f:
self.logger.debug(f"updating status: {status=}")
f.write(f"{status.name},{now}\n")

@property
def running(self):
Expand Down

0 comments on commit 5857e71

Please sign in to comment.