separate job package config from gitness types (#897)
This commit is contained in:
parent
d3fe654e23
commit
3dbaef0eb8
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue