feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -32,6 +32,12 @@ type Runner struct {
|
||||
registry *Registry
|
||||
opts RunnerOptions
|
||||
mu sync.Mutex
|
||||
stopping bool
|
||||
stopCtx context.Context
|
||||
cancel context.CancelFunc
|
||||
workers sync.WaitGroup
|
||||
stopOnce sync.Once
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func NewRunner(queue Queue, registry *Registry, opts RunnerOptions) *Runner {
|
||||
@@ -41,7 +47,30 @@ func NewRunner(queue Queue, registry *Registry, opts RunnerOptions) *Runner {
|
||||
if opts.Active == nil {
|
||||
opts.Active = new(atomic.Int64)
|
||||
}
|
||||
return &Runner{queue: queue, registry: registry, opts: opts}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
return &Runner{queue: queue, registry: registry, opts: opts, stopCtx: ctx, cancel: cancel, done: make(chan struct{})}
|
||||
}
|
||||
|
||||
// Stop closes admission permanently, cancels handlers and waits for persisted
|
||||
// completions. A timeout does not mean workers have exited: callers must keep
|
||||
// ownership/database resources alive and may call Stop again to await them.
|
||||
func (r *Runner) Stop(ctx context.Context) error {
|
||||
r.stopOnce.Do(func() {
|
||||
r.cancel()
|
||||
go func() {
|
||||
r.mu.Lock()
|
||||
r.stopping = true
|
||||
r.mu.Unlock()
|
||||
r.workers.Wait()
|
||||
close(r.done)
|
||||
}()
|
||||
})
|
||||
select {
|
||||
case <-r.done:
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) report(stage string, job *Job, err error) {
|
||||
@@ -57,7 +86,10 @@ func (r *Runner) Running() int64 { return r.opts.Active.Load() }
|
||||
func (r *Runner) Dispatch(ctx context.Context) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
for n := 0; n < 32 && ctx.Err() == nil; n++ {
|
||||
if r.stopping || r.stopCtx.Err() != nil {
|
||||
return
|
||||
}
|
||||
for n := 0; n < 32 && ctx.Err() == nil && r.stopCtx.Err() == nil; n++ {
|
||||
settings, err := r.queue.Settings(ctx)
|
||||
if err != nil {
|
||||
r.report("settings", nil, err)
|
||||
@@ -81,7 +113,15 @@ func (r *Runner) Dispatch(ctx context.Context) {
|
||||
}
|
||||
r.opts.Active.Add(1)
|
||||
r.report("start-log", job, r.queue.Started(ctx, job))
|
||||
go r.execute(ctx, job)
|
||||
workerCtx, cancel := context.WithCancel(ctx)
|
||||
stop := context.AfterFunc(r.stopCtx, cancel)
|
||||
r.workers.Add(1)
|
||||
go func() {
|
||||
defer r.workers.Done()
|
||||
defer cancel()
|
||||
defer stop()
|
||||
r.execute(workerCtx, job)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,53 @@ type finishedJob struct {
|
||||
err error
|
||||
at time.Time
|
||||
}
|
||||
|
||||
func TestRunnerStopWaitsAndClosesAdmission(t *testing.T) {
|
||||
q := newFakeQueue(1)
|
||||
reg := &Registry{}
|
||||
started := make(chan struct{})
|
||||
cancelled := make(chan struct{})
|
||||
exit := make(chan struct{})
|
||||
if err := reg.Register("synthetic", func(ctx context.Context, _ *Job) error {
|
||||
close(started)
|
||||
<-ctx.Done()
|
||||
close(cancelled)
|
||||
<-exit // simulate cleanup that cannot be interrupted
|
||||
return ctx.Err()
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := NewRunner(q, reg, RunnerOptions{})
|
||||
r.Dispatch(context.Background())
|
||||
receive(t, started)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
if err := r.Stop(ctx); !errors.Is(err, context.Canceled) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
receive(t, cancelled)
|
||||
if r.Running() != 1 {
|
||||
t.Fatal("worker exited before cleanup")
|
||||
}
|
||||
r.Dispatch(context.Background())
|
||||
if q.claimed != 1 {
|
||||
t.Fatal("admission remained open")
|
||||
}
|
||||
close(exit)
|
||||
ctx, cancel = context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := r.Stop(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
receive(t, q.finished)
|
||||
if r.Running() != 0 {
|
||||
t.Fatal("worker slot retained after stop")
|
||||
}
|
||||
if err := r.Stop(ctx); err != nil {
|
||||
t.Fatal("idempotent stop", err)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeQueue struct {
|
||||
mu sync.Mutex
|
||||
settings Settings
|
||||
|
||||
@@ -13,6 +13,8 @@ var (
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
// ClaimToken fences native database completion; never expose it to clients.
|
||||
ClaimToken string `json:"-"`
|
||||
UUID string `json:"uuid"`
|
||||
EventUUID string `json:"event_uuid,omitempty"`
|
||||
Type string `json:"event_type"`
|
||||
|
||||
Reference in new issue
Block a user