Skip to content

Commit

Permalink
fix: remove cycle import and set default timout
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Luthfi Fahlevi committed Sep 2, 2024
1 parent 715011a commit 9ee9390
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type Config struct {

type Asset struct {
AdditionalTypes []string `mapstructure:"additional_types"`
DeleteAssetsTimeout time.Duration `mapstructure:"delete_assets_timeout"`
DeleteAssetsTimeout time.Duration `mapstructure:"delete_assets_timeout" default:"5m"`
}

func LoadConfig() (*Config, error) {
Expand Down
12 changes: 6 additions & 6 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ func runServer(ctx context.Context, cfg *Config) error {
}()

assetService, cancel := asset.NewService(asset.ServiceDeps{
AssetRepo: assetRepository,
DiscoveryRepo: discoveryRepository,
LineageRepo: lineageRepository,
Worker: wrkr,
Logger: logger,
AssetConfig: cfg.Asset,
AssetRepo: assetRepository,
DiscoveryRepo: discoveryRepository,
LineageRepo: lineageRepository,
Worker: wrkr,
Logger: logger,
DeleteAssetsTimeout: cfg.Asset.DeleteAssetsTimeout,
})
defer cancel()

Expand Down
19 changes: 9 additions & 10 deletions core/asset/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/google/uuid"
"github.com/goto/compass/cli"
"github.com/goto/compass/pkg/queryexpr"
"github.com/goto/salt/log"
"go.opentelemetry.io/otel"
Expand All @@ -20,7 +19,7 @@ type Service struct {
lineageRepository LineageRepository
worker Worker
logger log.Logger
assetConfig cli.Asset
deleteAssetsTimeout time.Duration
cancelFnList []func()

assetOpCounter metric.Int64Counter
Expand All @@ -37,12 +36,12 @@ type Worker interface {
}

type ServiceDeps struct {
AssetRepo Repository
DiscoveryRepo DiscoveryRepository
LineageRepo LineageRepository
Worker Worker
Logger log.Logger
AssetConfig cli.Asset
AssetRepo Repository
DiscoveryRepo DiscoveryRepository
LineageRepo LineageRepository
Worker Worker
Logger log.Logger
DeleteAssetsTimeout time.Duration
}

func NewService(deps ServiceDeps) (service *Service, cancel func()) {
Expand All @@ -58,7 +57,7 @@ func NewService(deps ServiceDeps) (service *Service, cancel func()) {
lineageRepository: deps.LineageRepo,
worker: deps.Worker,
logger: deps.Logger,
assetConfig: deps.AssetConfig,
deleteAssetsTimeout: deps.DeleteAssetsTimeout,
cancelFnList: make([]func(), 0),

assetOpCounter: assetOpCounter,
Expand Down Expand Up @@ -154,7 +153,7 @@ func (s *Service) DeleteAssets(ctx context.Context, request DeleteAssetsRequest)
}

if !request.DryRun && total > 0 {
newCtx, cancel := context.WithTimeout(context.Background(), s.assetConfig.DeleteAssetsTimeout)
newCtx, cancel := context.WithTimeout(context.Background(), s.deleteAssetsTimeout)
s.cancelFnList = append(s.cancelFnList, cancel)
go s.executeDeleteAssets(newCtx, deleteSQLExpr)
}
Expand Down

0 comments on commit 9ee9390

Please sign in to comment.