From 3dbaef0eb84f0d6f0c115d120d0399cd688605d4 Mon Sep 17 00:00:00 2001 From: Atefeh Mohseni-Ejiyeh Date: Wed, 13 Dec 2023 06:15:09 +0000 Subject: [PATCH] separate job package config from gitness types (#897) --- cli/server/config.go | 9 +++++++++ cmd/gitness/wire.go | 1 + cmd/gitness/wire_gen.go | 3 ++- job/config.go | 30 ++++++++++++++++++++++++++++++ job/wire.go | 7 +++---- 5 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 job/config.go diff --git a/cli/server/config.go b/cli/server/config.go index 9aa1d32f1..e6034098b 100644 --- a/cli/server/config.go +++ b/cli/server/config.go @@ -31,6 +31,7 @@ import ( "github.com/harness/gitness/blob" "github.com/harness/gitness/events" gittypes "github.com/harness/gitness/git/types" + "github.com/harness/gitness/job" "github.com/harness/gitness/lock" "github.com/harness/gitness/pubsub" "github.com/harness/gitness/store/database" @@ -361,3 +362,11 @@ func ProvideKeywordSearchConfig(config *types.Config) keywordsearch.Config { MaxRetries: config.KeywordSearch.MaxRetries, } } + +func ProvideJobsConfig(config *types.Config) job.Config { + return job.Config{ + InstanceID: config.InstanceID, + BackgroundJobsMaxRunning: config.BackgroundJobs.MaxRunning, + BackgroundJobsRetentionTime: config.BackgroundJobs.RetentionTime, + } +} diff --git a/cmd/gitness/wire.go b/cmd/gitness/wire.go index 95eb111e0..709c2b918 100644 --- a/cmd/gitness/wire.go +++ b/cmd/gitness/wire.go @@ -141,6 +141,7 @@ func initSystem(ctx context.Context, config *types.Config) (*cliserver.System, e cliserver.ProvideCleanupConfig, cleanup.WireSet, codecomments.WireSet, + cliserver.ProvideJobsConfig, job.WireSet, protection.WireSet, checkcontroller.WireSet, diff --git a/cmd/gitness/wire_gen.go b/cmd/gitness/wire_gen.go index d5d032639..d1b38e871 100644 --- a/cmd/gitness/wire_gen.go +++ b/cmd/gitness/wire_gen.go @@ -155,7 +155,8 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro executor := job.ProvideExecutor(jobStore, pubSub) lockConfig := server.ProvideLockConfig(config) mutexManager := lock.ProvideMutexManager(lockConfig, universalClient) - jobScheduler, err := job.ProvideScheduler(jobStore, executor, mutexManager, pubSub, config) + jobConfig := server.ProvideJobsConfig(config) + jobScheduler, err := job.ProvideScheduler(jobStore, executor, mutexManager, pubSub, jobConfig) if err != nil { return nil, err } diff --git a/job/config.go b/job/config.go new file mode 100644 index 000000000..ca7ec66b0 --- /dev/null +++ b/job/config.go @@ -0,0 +1,30 @@ +// Copyright 2023 Harness, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package job + +import "time" + +type Config struct { + // InstanceID specifis the ID of the instance. + InstanceID string `envconfig:"INSTANCE_ID"` + + // MaxRunning is maximum number of jobs that can be running at once. + BackgroundJobsMaxRunning int `envconfig:"JOBS_MAX_RUNNING" default:"10"` + + // RetentionTime is the duration after which non-recurring, + // finished and failed jobs will be purged from the DB. + BackgroundJobsRetentionTime time.Duration `envconfig:"JOBS_RETENTION_TIME" default:"120h"` // 5 days + +} diff --git a/job/wire.go b/job/wire.go index b8c65ba70..f437f0ab4 100644 --- a/job/wire.go +++ b/job/wire.go @@ -17,7 +17,6 @@ package job import ( "github.com/harness/gitness/lock" "github.com/harness/gitness/pubsub" - "github.com/harness/gitness/types" "github.com/google/wire" ) @@ -42,7 +41,7 @@ func ProvideScheduler( executor *Executor, mutexManager lock.MutexManager, pubsubService pubsub.PubSub, - config *types.Config, + config Config, ) (*Scheduler, error) { return NewScheduler( store, @@ -50,7 +49,7 @@ func ProvideScheduler( mutexManager, pubsubService, config.InstanceID, - config.BackgroundJobs.MaxRunning, - config.BackgroundJobs.RetentionTime, + config.BackgroundJobsMaxRunning, + config.BackgroundJobsRetentionTime, ) }