Confirmation + Controlling API add
This commit is contained in:
@@ -27,14 +27,13 @@ type LokiInfo struct {
|
||||
// @Description get logs
|
||||
// @Param body body models.compute true "The compute content"
|
||||
// @Success 200 {workspace} models.workspace
|
||||
// @router / [post]
|
||||
// @router /:id [post]
|
||||
func (o *LokiController) GetLogs() {
|
||||
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
var resp map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &resp)
|
||||
|
||||
path := "/loki/api/v1/query_range"
|
||||
|
||||
if len(resp) > 0 {
|
||||
start := fmt.Sprintf("%v", resp["start"])
|
||||
if len(start) > 10 {
|
||||
@@ -44,7 +43,9 @@ func (o *LokiController) GetLogs() {
|
||||
if len(end) > 10 {
|
||||
end = end[0:10]
|
||||
}
|
||||
query := []string{}
|
||||
query := []string{
|
||||
"workflow_execution_id=\"" + id + "\"",
|
||||
}
|
||||
for k, v := range resp {
|
||||
if k == "start" || k == "end" {
|
||||
continue
|
||||
@@ -96,6 +97,10 @@ func (o *LokiController) GetLogs() {
|
||||
// The server connects to Loki's /loki/api/v1/tail WebSocket endpoint and
|
||||
// forwards every message it receives until the client disconnects.
|
||||
func LogsStreamHandler(w http.ResponseWriter, r *http.Request) {
|
||||
execID := strings.TrimSuffix(
|
||||
strings.TrimPrefix(r.URL.Path, "/oc/logs/"),
|
||||
"",
|
||||
)
|
||||
conn, err := wsUpgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -112,7 +117,9 @@ func LogsStreamHandler(w http.ResponseWriter, r *http.Request) {
|
||||
start = start[:10]
|
||||
}
|
||||
|
||||
var labels []string
|
||||
labels := []string{
|
||||
"workflow_execution_id=\"" + execID + "\"",
|
||||
}
|
||||
for k, v := range query {
|
||||
if k == "start" || k == "end" {
|
||||
continue
|
||||
|
||||
@@ -198,6 +198,10 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
|
||||
schedulerMu.Unlock()
|
||||
|
||||
if updated.Confirm {
|
||||
// Subscribe BEFORE calling Schedule to avoid missing the notification.
|
||||
confirmCh, confirmUnsub := infrastructure.SubscribeSessionConfirmation(executionsID)
|
||||
defer confirmUnsub()
|
||||
|
||||
workflowScheduler.UUID = executionsID
|
||||
_, _, _, schedErr := infrastructure.Schedule(&workflowScheduler, wfID, req)
|
||||
if schedErr != nil {
|
||||
@@ -206,8 +210,23 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
return
|
||||
}
|
||||
fmt.Println("UPDATE CONFIRM — waiting for execution confirmation")
|
||||
select {
|
||||
case <-confirmCh:
|
||||
_ = conn.WriteJSON(map[string]interface{}{
|
||||
"confirmed": true,
|
||||
"scheduling_id": executionsID,
|
||||
})
|
||||
case <-time.After(60 * time.Second):
|
||||
_ = conn.WriteJSON(map[string]interface{}{
|
||||
"confirmed": false,
|
||||
"error": "confirmation timeout: scheduling accepted but peers did not confirm in time",
|
||||
})
|
||||
case <-ctx.Done():
|
||||
// client disconnected before confirmation
|
||||
}
|
||||
confirmed = true
|
||||
fmt.Println("UPDATE CONFIRM")
|
||||
fmt.Println("UPDATE CONFIRM done")
|
||||
return
|
||||
}
|
||||
// Detect mode change before updating local vars.
|
||||
|
||||
@@ -85,6 +85,30 @@ func (o *WorkflowExecutionController) Get() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description find workflow by workflowid
|
||||
// @Param id path string true "the workflowid you want to get"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /:id [delete]
|
||||
func (o *WorkflowExecutionController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
data := oclib.NewRequest(collection, user, peerID, groups, nil).LoadOne(id)
|
||||
if b := data.ToBookings(); b != nil {
|
||||
bAccess := oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.BOOKING), nil)
|
||||
s := bAccess.Search(&dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"execution_id": {{Operator: dbs.EQUAL.String(), Value: b.ExecutionID}},
|
||||
},
|
||||
}, "", false, 0, 10000)
|
||||
for _, ss := range s.Data {
|
||||
bAccess.DeleteOne(ss.GetID())
|
||||
}
|
||||
}
|
||||
o.Data["json"] = oclib.NewRequest(collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search
|
||||
// @Description find compute by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
|
||||
Reference in New Issue
Block a user