This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
start.go
62 lines (51 loc) · 2.15 KB
/
start.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
package scheduler
import (
"context"
"fmt"
"runtime/debug"
"github.com/flyteorg/flyteadmin/pkg/repositories"
"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
"github.com/flyteorg/flyteadmin/pkg/runtime"
"github.com/flyteorg/flyteidl/clients/go/admin"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flytestdlib/promutils"
)
// StartScheduler creates and starts a new scheduler instance. This is a blocking call and will block the calling go-routine
func StartScheduler(ctx context.Context) error {
configuration := runtime.NewConfigurationProvider()
applicationConfiguration := configuration.ApplicationConfiguration().GetTopLevelConfig()
// Define the schedulerScope for prometheus metrics
schedulerScope := promutils.NewScope(applicationConfiguration.MetricsScope).NewSubScope("flytescheduler")
schedulerPanics := schedulerScope.MustNewCounter("initialization_panic",
"panics encountered initializing the flyte native scheduler")
defer func() {
if err := recover(); err != nil {
schedulerPanics.Inc()
logger.Fatalf(ctx, fmt.Sprintf("caught panic: %v [%+v]", err, string(debug.Stack())))
}
}()
databaseConfig := configuration.ApplicationConfiguration().GetDbConfig()
logConfig := logger.GetConfig()
db, err := repositories.GetDB(ctx, databaseConfig, logConfig)
if err != nil {
logger.Fatal(ctx, err)
}
dbScope := schedulerScope.NewSubScope("database")
repo := repositories.NewGormRepo(
db, errors.NewPostgresErrorTransformer(schedulerScope.NewSubScope("errors")), dbScope)
clientSet, err := admin.ClientSetBuilder().WithConfig(admin.GetConfig(ctx)).Build(ctx)
if err != nil {
logger.Fatalf(ctx, "Flyte native scheduler failed to start due to %v", err)
return err
}
adminServiceClient := clientSet.AdminClient()
scheduleExecutor := NewScheduledExecutor(repo,
configuration.ApplicationConfiguration().GetSchedulerConfig().GetWorkflowExecutorConfig(), schedulerScope, adminServiceClient)
logger.Info(ctx, "Successfully initialized a native flyte scheduler")
err = scheduleExecutor.Run(ctx)
if err != nil {
logger.Fatalf(ctx, "Flyte native scheduler failed to start due to %v", err)
return err
}
return nil
}