-
Notifications
You must be signed in to change notification settings - Fork 1
/
create.go
80 lines (65 loc) · 1.63 KB
/
create.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
config "pubsubroller/config"
"pubsubroller/subscription"
"pubsubroller/topic"
)
func createSubscriptions(client pubsubClient, callbacks SubscriptionCallbacks, ctx context.Context, conf config.Configuration, opts appOptions) {
subscriptions := subscription.FromConfig(conf, opts.Variables)
counter := counter{}
egSubscriptions := errgroup.Group{}
callbacks.Initialized()
for _, sub := range subscriptions {
sub := sub
egSubscriptions.Go(func() error {
if !opts.IsDryRun {
if err := client.CreateSubscription(sub); err != nil {
if errors.Cause(err) == subscription.SUBSCRIPTION_EXISTS_ERR {
counter.Skipped()
return nil
} else {
return err
}
}
}
counter.Done()
callbacks.Each(sub)
return nil
})
}
if err := egSubscriptions.Wait(); err != nil {
panic(err)
}
callbacks.Finalized(&counter)
}
func createTopics(client pubsubClient, callbacks TopicCallbacks, ctx context.Context, conf config.Configuration, opts appOptions) {
topics := topic.FromConfig(conf, opts.Variables)
counter := counter{}
egTopics := errgroup.Group{}
callbacks.Initialized()
for _, tp := range topics {
tp := tp
egTopics.Go(func() error {
if !opts.IsDryRun {
if err := client.CreateTopic(tp); err != nil {
if errors.Cause(err) == topic.TOPIC_EXISTS_ERR {
counter.Skipped()
return nil
} else {
return err
}
}
}
counter.Done()
callbacks.Each(tp)
return nil
})
}
if err := egTopics.Wait(); err != nil {
panic(err)
}
callbacks.Finalized(&counter)
}