This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workers.go
64 lines (52 loc) · 1.77 KB
/
workers.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
package main
import (
"cadence-poc/cadence/gitops"
"cadence-poc/cadence/prepare_gitops"
"cadence-poc/cadence/workers"
"flag"
"go.uber.org/cadence/worker"
"go.uber.org/zap"
"os"
)
var (
domain = os.Getenv("CADENCE_DOMAIN")
preparerTaskList = os.Getenv("PREPARER_TASK_LIST")
preparerName = os.Getenv("PREPARER_NAME")
cronTaskList = os.Getenv("CRON_TASK_LIST")
cronName = os.Getenv("CRON_NAME")
)
func main() {
// Declare CLI arguments
var mode string
flag.StringVar(&mode, "m", "", "Mode is preparer or gitops.")
flag.Parse()
// Create Cadence Worker
var c workers.CadenceAdapter
c.Setup()
workerOptions := worker.Options{
MetricsScope: c.Scope,
Logger: c.Logger,
}
var cadenceWorker worker.Worker
// Register workflow & activities based on the mode we run
switch mode {
case "preparer":
cadenceWorker = worker.New(c.ServiceClient, domain, preparerTaskList, workerOptions)
cadenceWorker.RegisterWorkflow(prepare_gitops.PrepareGitOps)
cadenceWorker.RegisterActivity(gitops.ValidateKeyFile)
case "gitops":
cadenceWorker = worker.New(c.ServiceClient, domain, cronTaskList, workerOptions)
cadenceWorker.RegisterWorkflow(gitops.GitOpsCron)
cadenceWorker.RegisterActivity(gitops.DeployWaitingKeys)
_ = os.Getenv("CRON_STRING")
//TODO: use cronStr: see https://github.com/uber-common/cadence-samples/blob/master/cmd/samples/cron/
}
// Start the worker
err := cadenceWorker.Start()
if err != nil {
c.Logger.Error("Failed to start workers.", zap.Error(err))
panic("Failed to start workers")
}
// The workers are supposed to be long running process that should not exit.
select {}
}