Skip to content

Commit

Permalink
feat: studio one man queue
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbx9da4 committed Aug 29, 2024
1 parent d4bbfe0 commit 45670a6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/studio/studioHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type StudioHandlers struct {
OverlayPath string
Ctx context.Context
mutex sync.Mutex
syncCondition *sync.Cond
mutexCondition *sync.Cond
running bool
}

Expand All @@ -59,33 +59,33 @@ func NewStudioHandlers(ctx context.Context, workflowRunner *run.Workflow) (*Stud
}

ret.mutex = sync.Mutex{}
ret.syncCondition = sync.NewCond(&ret.mutex)
ret.mutexCondition = sync.NewCond(&ret.mutex)

return ret, nil
}

func (h *StudioHandlers) getLastCompletedRunResult(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
h.syncCondition.L.Lock()
h.mutexCondition.L.Lock()
for h.running {
h.syncCondition.Wait()
h.mutexCondition.Wait()
}
defer h.syncCondition.L.Unlock()
defer h.mutexCondition.L.Unlock()

return h.getLastCompletedRunResultInner(ctx, w, r)
}

func (h *StudioHandlers) reRun(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
// Wait for the run to finish
h.syncCondition.L.Lock()
h.mutexCondition.L.Lock()
for h.running {
h.syncCondition.Wait()
h.mutexCondition.Wait()
}

h.running = true
defer func() {
h.running = false
h.syncCondition.Broadcast()
h.syncCondition.L.Unlock()
h.mutexCondition.Broadcast()
h.mutexCondition.L.Unlock()
}()

cloned, err := h.WorkflowRunner.Clone(h.Ctx, run.WithSkipCleanup(), run.WithLinting())
Expand Down

0 comments on commit 45670a6

Please sign in to comment.