-
Notifications
You must be signed in to change notification settings - Fork 948
/
Copy pathplugin.go
68 lines (55 loc) · 1.36 KB
/
plugin.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
package feeds
import (
"strings"
"sync"
"github.com/botlabs-gg/yagpdb/v2/common"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type Plugin interface {
common.Plugin
StartFeed()
StopFeed(*sync.WaitGroup)
}
var (
runningPlugins = make([]Plugin, 0)
logger = common.GetFixedPrefixLogger("feeds")
)
// Run runs the specified feeds
func Run(which []string) {
for _, plugin := range common.Plugins {
fp, ok := plugin.(Plugin)
if !ok {
continue
}
if len(which) > 0 {
found := false
for _, feed := range which {
if strings.EqualFold(feed, plugin.PluginInfo().Name) {
found = true
break
}
}
if !found {
logger.Info("Ignoring feed ", plugin.PluginInfo().Name)
continue
}
}
logger.Info("Starting feed ", plugin.PluginInfo().Name)
go fp.StartFeed()
runningPlugins = append(runningPlugins, fp)
}
joined := strings.Join(which, ",")
common.ServiceTracker.RegisterService(common.ServiceTypeFeed, "Feeds", joined, nil)
}
func Stop(wg *sync.WaitGroup) {
for _, plugin := range runningPlugins {
logger.Info("Stopping feed ", plugin.PluginInfo().Name)
wg.Add(1)
go plugin.StopFeed(wg)
}
}
var MetricPostedMessages = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "yagpdb_feed_posted_total",
Help: "Feed messages posted",
}, []string{"source"})