generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
compaction.go
47 lines (40 loc) · 1.09 KB
/
compaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package verity
import (
"context"
"github.com/dogmatiq/configkit"
"github.com/dogmatiq/verity/handler/projection"
"github.com/dogmatiq/verity/internal/x/loggingx"
"golang.org/x/sync/errgroup"
)
// runCompactorsForApp runs a compactor for each projection within a specific
// application.
func (e *Engine) runCompactorsForApp(ctx context.Context, a *app) error {
g, ctx := errgroup.WithContext(ctx)
for _, h := range a.Config.RichHandlers().Projections() {
h := h // capture loop variable
g.Go(func() error {
return e.runCompactorForProjection(ctx, h, a)
})
}
return g.Wait()
}
// runCompactorForProjection runs a compactor for a specific projection.
func (e *Engine) runCompactorForProjection(
ctx context.Context,
h configkit.RichProjection,
a *app,
) error {
c := &projection.Compactor{
Handler: h.Handler(),
Interval: e.opts.ProjectionCompactInterval,
Timeout: e.opts.ProjectionCompactTimeout,
Semaphore: e.semaphore,
Logger: loggingx.WithPrefix(
e.logger,
"[compactor %s@%s] ",
h.Identity().Name,
a.Config.Identity().Name,
),
}
return c.Run(ctx)
}