-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (40 loc) · 938 Bytes
/
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
// This program fetches the full metadata for LOC.gov items.
package main
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
log "github.com/sirupsen/logrus"
)
var app = &App{}
func main() {
ctx, cancel := context.WithCancel(context.Background())
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
// Clean up function that will be called at program end no matter what
defer func() {
signal.Stop(quit)
cancel()
}()
// Listen for shutdown signals in a go-routine and cancel context then
go func() {
select {
case <-quit:
log.Info("Shutdown signal received; quitting item metadata fetcher")
cancel()
case <-ctx.Done():
}
}()
err := app.Init(ctx)
if err != nil {
log.Fatal("Error initializing application: ", err)
}
defer app.Shutdown()
// Process items with unfetched metadata
wg := &sync.WaitGroup{}
wg.Add(1)
go ProcessUnfetched(ctx, wg)
wg.Wait()
}