-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.go
63 lines (54 loc) · 1.61 KB
/
main.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
package main
import (
"context"
"net/http"
"os"
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/ossf/package-feeds/pkg/config"
"github.com/ossf/package-feeds/pkg/scheduler"
)
func main() {
// Increase idle conns per host to increase the reuse of existing
// connections between requests. This only applies to HTTP1. HTTP2 requests
// are multiplexed over a single TCP connection. HTTP2 is supported by
// all the current feeds.
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = 8
configPath, useConfig := os.LookupEnv("PACKAGE_FEEDS_CONFIG_PATH")
var err error
var appConfig *config.ScheduledFeedConfig
if useConfig {
appConfig, err = config.FromFile(configPath)
log.Infof("Using config from file: %v", configPath)
} else {
appConfig = config.Default()
log.Info("No config specified, using default configuration")
}
if err != nil {
log.Fatal(err)
}
pub, err := appConfig.PubConfig.ToPublisher(context.TODO())
if err != nil {
log.Fatalf("Failed to initialize publisher from config: %v", err)
}
log.Infof("Using %q publisher", pub.Name())
scheduledFeeds, err := appConfig.GetScheduledFeeds()
feedNames := []string{}
for k := range scheduledFeeds {
feedNames = append(feedNames, k)
}
log.Infof("Watching feeds: %v", strings.Join(feedNames, ", "))
if err != nil {
log.Fatal(err)
}
pollRate, err := time.ParseDuration(appConfig.PollRate)
if err != nil {
log.Fatalf("Failed to parse poll_rate to duration: %v", err)
}
sched := scheduler.New(scheduledFeeds, pub, appConfig.HTTPPort)
err = sched.Run(pollRate, appConfig.Timer)
if err != nil {
log.Fatal(err)
}
}