Scheduler + Observe

This commit is contained in:
mr
2026-04-29 07:45:41 +02:00
parent 4b9b1b8b91
commit 3be023b9af
20 changed files with 1006 additions and 87 deletions

View File

@@ -71,6 +71,7 @@ func realPushCheckfunc(ctx context.Context, conn *gorillaws.Conn, req *tools.API
go func() {
select {
case <-ctx.Done():
infrastructure.CleanupSession(executionsID, req)
// Session closed before timer fired — nothing to do, CleanupSession
// has already run (or will run) in the defer of CheckStreamHandler.
return
@@ -87,6 +88,7 @@ func realPushCheckfunc(ctx context.Context, conn *gorillaws.Conn, req *tools.API
// CheckStreamHandler is the WebSocket handler for slot availability checking.
// Query params: as_possible=true, preemption=true
func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("qksbdkqbsdkh")
var err error
wfID := strings.TrimSuffix(
strings.TrimPrefix(r.URL.Path, "/oc/check/"),
@@ -97,7 +99,7 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
asap := q.Get("as_possible") == "true"
preemption := q.Get("preemption") == "true"
user, peerID, groups := oclib.ExtractTokenInfo(*r)
user, peerID, groups := oclib.ExtractTokenInfoWs(*r)
req := &tools.APIRequest{
Username: user,
PeerID: peerID,
@@ -205,6 +207,7 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
workflowScheduler.UUID = executionsID
_, _, _, schedErr := infrastructure.Schedule(&workflowScheduler, wfID, req)
if schedErr != nil {
infrastructure.CleanupSession(executionsID, req)
_ = conn.WriteJSON(map[string]interface{}{
"error": schedErr.Error(),
})
@@ -213,8 +216,10 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("UPDATE CONFIRM — waiting for execution confirmation")
select {
case <-confirmCh:
fmt.Println("UPDATE CONFIRM done")
confirmed = true
_ = conn.WriteJSON(map[string]interface{}{
"confirmed": true,
"confirmed": true,
"scheduling_id": executionsID,
})
case <-time.After(60 * time.Second):
@@ -225,8 +230,10 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
case <-ctx.Done():
// client disconnected before confirmation
}
confirmed = true
fmt.Println("UPDATE CONFIRM done")
if !confirmed {
infrastructure.CleanupSession(executionsID, req)
fmt.Println("UPDATE CONFIRM not done")
}
return
}
// Detect mode change before updating local vars.
@@ -249,7 +256,8 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
!reflect.DeepEqual(updated.SelectedInstances, workflowScheduler.SelectedInstances) ||
!reflect.DeepEqual(updated.SelectedPartnerships, workflowScheduler.SelectedPartnerships) ||
!reflect.DeepEqual(updated.SelectedBuyings, workflowScheduler.SelectedBuyings) ||
!reflect.DeepEqual(updated.SelectedStrategies, workflowScheduler.SelectedStrategies)
!reflect.DeepEqual(updated.SelectedStrategies, workflowScheduler.SelectedStrategies) ||
!reflect.DeepEqual(updated.SelectedEmbeddedStorages, workflowScheduler.SelectedEmbeddedStorages)
infrastructure.CleanupSession(executionsID, req)