-
-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathquery.go
More file actions
42 lines (36 loc) · 1.03 KB
/
query.go
File metadata and controls
42 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package executor
import (
"github.com/dstackai/dstack/runner/internal/schemas"
)
func (ex *RunExecutor) GetJobWsLogsHistory() []schemas.LogEvent {
return ex.jobWsLogs.history
}
func (ex *RunExecutor) GetHistory(timestamp int64) *schemas.PullResponse {
return &schemas.PullResponse{
JobStates: eventsAfter(ex.jobStateHistory, timestamp),
JobLogs: eventsAfter(ex.jobLogs.history, timestamp),
RunnerLogs: eventsAfter(ex.runnerLogs.history, timestamp),
LastUpdated: ex.timestamp.GetLatest(),
NoConnectionsSecs: ex.connectionTracker.GetNoConnectionsSecs(),
HasMore: ex.state != WaitLogsFinished,
}
}
func (ex *RunExecutor) GetRunnerState() string {
return ex.state
}
type OrderedEvent interface {
GetTimestamp() int64
}
func eventsAfter[T OrderedEvent](events []T, timestamp int64) []T {
left := 0
right := len(events)
for left < right {
mid := (left + right) / 2
if events[mid].GetTimestamp() <= timestamp {
left = mid + 1
} else {
right = mid
}
}
return events[left:]
}