forked from microsoft/durabletask-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (44 loc) · 1.55 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
package main
import (
"context"
"flag"
"fmt"
"log"
"net"
"google.golang.org/grpc"
"github.com/microsoft/durabletask-go/backend"
"github.com/microsoft/durabletask-go/backend/sqlite"
)
var (
port = flag.Int("port", 4001, "The server port")
host = flag.String("host", "localhost", "The host to bind to")
dbFilePath = flag.String("db", "", "The path to the sqlite file to use (or create if not exists)")
ctx = context.Background()
)
func main() {
// Parse command-line arguments
flag.Parse()
grpcServer := grpc.NewServer()
worker := createTaskHubWorker(grpcServer, *dbFilePath, backend.DefaultLogger())
if err := worker.Start(ctx); err != nil {
log.Fatalf("failed to start worker: %v", err)
}
lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", *host, *port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
fmt.Printf("server listening at %v\n", lis.Addr())
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}
func createTaskHubWorker(server *grpc.Server, sqliteFilePath string, logger backend.Logger) backend.TaskHubWorker {
sqliteOptions := sqlite.NewSqliteOptions(sqliteFilePath)
be := sqlite.NewSqliteBackend(sqliteOptions, logger)
executor, registerFn := backend.NewGrpcExecutor(be, logger)
registerFn(server)
orchestrationWorker := backend.NewOrchestrationWorker(be, executor, logger)
activityWorker := backend.NewActivityTaskWorker(be, executor, logger)
taskHubWorker := backend.NewTaskHubWorker(be, orchestrationWorker, activityWorker, logger)
return taskHubWorker
}