Scheduling Node
This commit is contained in:
24
ws.go
24
ws.go
@@ -23,7 +23,7 @@ func main() {
|
||||
// ws://localhost:8090/oc/<workflow-id>/check
|
||||
// ws://localhost:8090/oc/<workflow-id>/check?as_possible=true
|
||||
// ws://localhost:8090/oc/<workflow-id>/check?as_possible=true&preemption=true
|
||||
url := "ws://localhost:8090/oc/WORKFLOW_ID/check?as_possible=true"
|
||||
url := "ws://localhost:8090/oc/58314c99-c595-4ca2-8b5e-822a6774efed/check?as_possible=true"
|
||||
token := ""
|
||||
// Body JSON envoyé comme premier message WebSocket (WorkflowSchedule).
|
||||
// Seuls start + duration_s sont requis si as_possible=true.
|
||||
@@ -80,6 +80,14 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
// Après 5 secondes, simule un changement de date côté front (now + 3 min).
|
||||
dateChangeTick := time.NewTimer(10 * time.Second)
|
||||
defer dateChangeTick.Stop()
|
||||
|
||||
// Après 15 secondes, simule la confirmation du scheduling par le client.
|
||||
confirmTick := time.NewTimer(15 * time.Second)
|
||||
defer confirmTick.Stop()
|
||||
|
||||
idleTimer := time.NewTimer(time.Duration(*timeout) * time.Second)
|
||||
defer idleTimer.Stop()
|
||||
|
||||
@@ -94,6 +102,20 @@ func main() {
|
||||
case <-idleTimer.C:
|
||||
fmt.Printf("Timeout (%ds) — aucun message reçu, fermeture.\n", *timeout)
|
||||
return
|
||||
case <-dateChangeTick.C:
|
||||
newStart := time.Now().UTC().Add(3 * time.Minute)
|
||||
update := `{"start":"` + newStart.Format(time.RFC3339) + `","duration_s":3600}`
|
||||
fmt.Printf("\n[sim] Envoi mise à jour de date → %s\n\n", update)
|
||||
if err := websocket.Message.Send(ws, update); err != nil {
|
||||
fmt.Printf("Erreur envoi mise à jour : %v\n", err)
|
||||
return
|
||||
}
|
||||
case <-confirmTick.C:
|
||||
fmt.Println("\n[sim] Envoi confirmation du scheduling → {\"confirm\":true}\n")
|
||||
if err := websocket.Message.Send(ws, `{"confirm":true}`); err != nil {
|
||||
fmt.Printf("Erreur envoi confirmation : %v\n", err)
|
||||
return
|
||||
}
|
||||
case raw := <-msgs:
|
||||
idleTimer.Reset(time.Duration(*timeout) * time.Second)
|
||||
var data any
|
||||
|
||||
Reference in New Issue
Block a user