/
execution_event_repo.go
39 lines (33 loc) · 1.07 KB
/
execution_event_repo.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
package gormimpl
import (
"context"
"gorm.io/gorm"
"github.com/flyteorg/flyte/flyteadmin/pkg/repositories/errors"
"github.com/flyteorg/flyte/flyteadmin/pkg/repositories/interfaces"
"github.com/flyteorg/flyte/flyteadmin/pkg/repositories/models"
"github.com/flyteorg/flyte/flytestdlib/promutils"
)
type ExecutionEventRepo struct {
db *gorm.DB
errorTransformer errors.ErrorTransformer
metrics gormMetrics
}
func (r *ExecutionEventRepo) Create(ctx context.Context, input models.ExecutionEvent) error {
timer := r.metrics.CreateDuration.Start()
tx := r.db.WithContext(ctx).Omit("id").Create(&input)
timer.Stop()
if tx.Error != nil {
return r.errorTransformer.ToFlyteAdminError(tx.Error)
}
return nil
}
// Returns an instance of ExecutionRepoInterface
func NewExecutionEventRepo(
db *gorm.DB, errorTransformer errors.ErrorTransformer, scope promutils.Scope) interfaces.ExecutionEventRepoInterface {
metrics := newMetrics(scope)
return &ExecutionEventRepo{
db: db,
errorTransformer: errorTransformer,
metrics: metrics,
}
}