This repository has no description
1package executor
2
3import (
4 "context"
5 "fmt"
6 "sync"
7
8 "tangled.org/core/spindle/engine"
9 "tangled.org/core/spindle/models"
10)
11
12// wraps a real engine so StartWorkflows gets the slot ReserveSeat already
13// acquired, not a second one. everything else delegates, the execution
14// path runs exactly like standalone
15type reservedEngine struct {
16 models.Engine
17 slot engine.WorkflowSlot
18 once sync.Once
19}
20
21func newReservedEngine(inner models.Engine, slot engine.WorkflowSlot) models.Engine {
22 return &reservedEngine{Engine: inner, slot: slot}
23}
24
25// hands back the pre-acquired slot exactly once, a second acquire would
26// double-count it
27func (e *reservedEngine) AcquireWorkflowSlot(ctx context.Context, wid models.WorkflowId, wf *models.Workflow, _ engine.AcquireMode) (engine.WorkflowSlot, error) {
28 var slot engine.WorkflowSlot
29 e.once.Do(func() {
30 slot = e.slot
31 e.slot = nil
32 })
33 if slot == nil {
34 return nil, fmt.Errorf("reserved slot already consumed")
35 }
36 return slot, nil
37}