-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (73 loc) · 1.89 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"flag"
"fmt"
"log"
"time"
"github.com/attwad/cdf/errorreport"
"github.com/attwad/cdf/health"
"github.com/attwad/cdf/indexer"
"github.com/attwad/cdf/money"
"github.com/attwad/cdf/pick"
"github.com/attwad/cdf/transcribe"
"github.com/attwad/cdf/upload"
"github.com/attwad/cdf/worker"
)
var (
projectID = flag.String("project_id", "", "Project ID")
bucket = flag.String("bucket", "", "Cloud storage bucket")
soxPath = flag.String("sox_path", "sox", "SOX binary path")
elasticAddress = flag.String("elastic_address", "http://elastic:9200", "HTTP address to elastic instance")
)
func main() {
flag.Parse()
ctx := context.Background()
er, err := errorreport.NewStackdriverReporter(ctx, *projectID, "worker")
if err != nil {
log.Fatalf("Creating error reporting client: %v", err)
}
defer er.Close()
p, err := pick.NewDatastorePicker(ctx, *projectID)
if err != nil {
log.Fatal(err)
}
u, err := upload.NewGCSFileUploader(ctx, *bucket)
if err != nil {
log.Fatal(err)
}
t, err := transcribe.NewGSpeechTranscriber(ctx)
if err != nil {
log.Fatal(err)
}
b, err := money.NewDatastoreBroker(ctx, *projectID)
if err != nil {
log.Fatal(err)
}
log.Println("Will connect to elastic instance @", *elasticAddress)
a := worker.NewGCPWorker(
u,
t,
b,
p,
indexer.NewElasticIndexer(*elasticAddress),
*soxPath,
health.NewElasticHealthChecker(*elasticAddress))
log.Println("Analyzer created, entering loop...")
for {
if err := a.Run(ctx); err != nil {
log.Println("[ERROR]: running:", err)
er.Report(fmt.Errorf("Running: %v", err))
}
hasNew, err := a.MaybeSchedule(ctx)
if err != nil {
log.Fatalf("Scheduling new tasks: %v", err)
er.Report(fmt.Errorf("Scheduling new task: %v", err))
}
// Only sleep if we have nothing scheduled.
if !hasNew {
log.Println("Sleeping...")
time.Sleep(1 * time.Minute)
}
}
}