Skip to content

Commit b892c05

Browse files
committed
Refactor async runnable initialization for dependency injection
Replaced direct initialization of async runnable with dependency injection across multiple services. This change improves testability and aligns with DI principles, ensuring better modularity and maintainability.
1 parent 785ce84 commit b892c05

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

cmd/external-app/wire_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/trigger/devtronApps/HandlerService.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/devtron-labs/devtron/pkg/app"
4141
bean4 "github.com/devtron-labs/devtron/pkg/app/bean"
4242
"github.com/devtron-labs/devtron/pkg/app/status"
43-
"github.com/devtron-labs/devtron/pkg/asyncProvider"
4443
"github.com/devtron-labs/devtron/pkg/attributes"
4544
"github.com/devtron-labs/devtron/pkg/auth/user"
4645
userBean "github.com/devtron-labs/devtron/pkg/auth/user/bean"
@@ -231,7 +230,7 @@ func NewHandlerServiceImpl(logger *zap.SugaredLogger,
231230
ciLogService pipeline.CiLogService,
232231
workflowService executor.WorkflowService,
233232
blobConfigStorageService pipeline.BlobStorageConfigService,
234-
) (*HandlerServiceImpl, error) {
233+
asyncRunnable *async.Runnable) (*HandlerServiceImpl, error) {
235234
impl := &HandlerServiceImpl{
236235
logger: logger,
237236
cdWorkflowCommonService: cdWorkflowCommonService,
@@ -297,7 +296,7 @@ func NewHandlerServiceImpl(logger *zap.SugaredLogger,
297296
ciLogService: ciLogService,
298297
workflowService: workflowService,
299298
blobConfigStorageService: blobConfigStorageService,
300-
asyncRunnable: asyncProvider.NewAsyncRunnable(logger),
299+
asyncRunnable: asyncRunnable,
301300
}
302301
config, err := types.GetCdConfig()
303302
if err != nil {

pkg/eventProcessor/in/WorkflowEventProcessorService.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828

2929
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
3030
"github.com/devtron-labs/common-lib/async"
31-
commonConstants "github.com/devtron-labs/common-lib/constants"
3231
pubsub "github.com/devtron-labs/common-lib/pubsub-lib"
3332
"github.com/devtron-labs/common-lib/pubsub-lib/model"
3433
"github.com/devtron-labs/common-lib/utils/registry"
@@ -131,7 +130,8 @@ func NewWorkflowEventProcessorImpl(logger *zap.SugaredLogger,
131130
ciArtifactRepository repository.CiArtifactRepository,
132131
cdWorkflowRepository pipelineConfig.CdWorkflowRepository,
133132
deploymentConfigService common.DeploymentConfigService,
134-
ciHandlerService trigger.HandlerService) (*WorkflowEventProcessorImpl, error) {
133+
ciHandlerService trigger.HandlerService,
134+
asyncRunnable *async.Runnable) (*WorkflowEventProcessorImpl, error) {
135135
impl := &WorkflowEventProcessorImpl{
136136
logger: logger,
137137
pubSubClient: pubSubClient,
@@ -160,7 +160,7 @@ func NewWorkflowEventProcessorImpl(logger *zap.SugaredLogger,
160160
cdWorkflowRepository: cdWorkflowRepository,
161161
deploymentConfigService: deploymentConfigService,
162162
ciHandlerService: ciHandlerService,
163-
asyncRunnable: async.NewAsyncRunnable(logger, commonConstants.Orchestrator),
163+
asyncRunnable: asyncRunnable,
164164
}
165165
appServiceConfig, err := app.GetAppServiceConfig()
166166
if err != nil {

pkg/variables/ScopedVariableService.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/caarlos0/env"
2727
"github.com/devtron-labs/common-lib/async"
2828
"github.com/devtron-labs/devtron/internal/sql/repository/app"
29-
"github.com/devtron-labs/devtron/pkg/asyncProvider"
3029
repository3 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
3130
"github.com/devtron-labs/devtron/pkg/cluster/repository"
3231
"github.com/devtron-labs/devtron/pkg/devtronResource/read"
@@ -62,13 +61,13 @@ type ScopedVariableServiceImpl struct {
6261
}
6362

6463
func NewScopedVariableServiceImpl(logger *zap.SugaredLogger, scopedVariableRepository repository2.ScopedVariableRepository, appRepository app.AppRepository, environmentRepository repository3.EnvironmentRepository, devtronResourceSearchableKeyService read.DevtronResourceSearchableKeyService, clusterRepository repository.ClusterRepository,
65-
qualifierMappingService resourceQualifiers.QualifierMappingService) (*ScopedVariableServiceImpl, error) {
64+
qualifierMappingService resourceQualifiers.QualifierMappingService, asyncRunnable *async.Runnable) (*ScopedVariableServiceImpl, error) {
6665
scopedVariableService := &ScopedVariableServiceImpl{
6766
logger: logger,
6867
scopedVariableRepository: scopedVariableRepository,
6968
qualifierMappingService: qualifierMappingService,
7069
VariableCache: &cache.VariableCacheObj{CacheLock: &sync.Mutex{}},
71-
asyncRunnable: asyncProvider.NewAsyncRunnable(logger),
70+
asyncRunnable: asyncRunnable,
7271
}
7372
cfg, err := GetVariableNameConfig()
7473
if err != nil {

wire_gen.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)