tinyrelayfile
tinyrelay/internal/daemon/work_guard.go/

internal/daemon/work_guard.go raw
1package daemon
2
3import (
4 "context"
5 "encoding/json"
6 "github.com/FelineStateMachine/tinyrelay/internal/replication"
7 "github.com/FelineStateMachine/tinyrelay/internal/work"
8)
9
10func (t *Tenant) guardWork(next work.Handler) work.Handler {
11 return func(ctx context.Context, intent work.Intent) error {
12 if intent.Kind == "job" {
13 var spec replication.JobSpec
14 if json.Unmarshal([]byte(intent.Payload), &spec) == nil && spec.Kind == replication.JobBackup {
15 // The snapshot provider acquires exclusive admission itself.
16 return next(ctx, intent)
17 }
18 }
19 ctx, done, err := t.beginOperation(ctx)
20 if err != nil {
21 return err
22 }
23 defer done()
24 return next(ctx, intent)
25 }
26}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs