-
Notifications
You must be signed in to change notification settings - Fork 0
/
register_cron.go
52 lines (40 loc) · 1.15 KB
/
register_cron.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
48
49
50
51
52
package flows
import (
"context"
"github.com/hjwalt/flows/runtime_cron"
"github.com/hjwalt/runway/inverse"
"github.com/hjwalt/runway/runtime"
)
const (
QualifierCron = "QualifierCron"
)
func RegisterCron(
container inverse.Container,
configs []runtime.Configuration[*runtime_cron.Cron],
) {
resolver := runtime.NewResolver[*runtime_cron.Cron, runtime.Runtime](
QualifierCron,
container,
true,
runtime_cron.NewCron,
)
resolver.AddConfig(ResolveCronConfigTaskProducer)
for _, config := range configs {
resolver.AddConfigVal(config)
}
resolver.Register()
RegisterRuntime(QualifierCron, container)
}
func ResolveCronConfigTaskProducer(ctx context.Context, ci inverse.Container) (runtime.Configuration[*runtime_cron.Cron], error) {
handler, getHandlerError := GetRabbitProducer(ctx, ci)
if getHandlerError != nil {
return nil, getHandlerError
}
return runtime_cron.WithTaskProducer(handler), nil
}
// ===================================
func RegisterCronConfig(ci inverse.Container, configs ...runtime.Configuration[*runtime_cron.Cron]) {
for _, config := range configs {
ci.AddVal(runtime.QualifierConfig(QualifierCron), config)
}
}