mirror of
https://github.com/harness/drone.git
synced 2025-05-05 23:42:57 +00:00
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/blob"
|
||||||
"github.com/harness/gitness/events"
|
"github.com/harness/gitness/events"
|
||||||
gittypes "github.com/harness/gitness/git/types"
|
gittypes "github.com/harness/gitness/git/types"
|
||||||
|
"github.com/harness/gitness/job"
|
||||||
"github.com/harness/gitness/lock"
|
"github.com/harness/gitness/lock"
|
||||||
"github.com/harness/gitness/pubsub"
|
"github.com/harness/gitness/pubsub"
|
||||||
"github.com/harness/gitness/store/database"
|
"github.com/harness/gitness/store/database"
|
||||||
@ -361,3 +362,11 @@ func ProvideKeywordSearchConfig(config *types.Config) keywordsearch.Config {
|
|||||||
MaxRetries: config.KeywordSearch.MaxRetries,
|
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,
|
cliserver.ProvideCleanupConfig,
|
||||||
cleanup.WireSet,
|
cleanup.WireSet,
|
||||||
codecomments.WireSet,
|
codecomments.WireSet,
|
||||||
|
cliserver.ProvideJobsConfig,
|
||||||
job.WireSet,
|
job.WireSet,
|
||||||
protection.WireSet,
|
protection.WireSet,
|
||||||
checkcontroller.WireSet,
|
checkcontroller.WireSet,
|
||||||
|
@ -155,7 +155,8 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||||||
executor := job.ProvideExecutor(jobStore, pubSub)
|
executor := job.ProvideExecutor(jobStore, pubSub)
|
||||||
lockConfig := server.ProvideLockConfig(config)
|
lockConfig := server.ProvideLockConfig(config)
|
||||||
mutexManager := lock.ProvideMutexManager(lockConfig, universalClient)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
30
job/config.go
Normal file
30
job/config.go
Normal file
@ -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 (
|
import (
|
||||||
"github.com/harness/gitness/lock"
|
"github.com/harness/gitness/lock"
|
||||||
"github.com/harness/gitness/pubsub"
|
"github.com/harness/gitness/pubsub"
|
||||||
"github.com/harness/gitness/types"
|
|
||||||
|
|
||||||
"github.com/google/wire"
|
"github.com/google/wire"
|
||||||
)
|
)
|
||||||
@ -42,7 +41,7 @@ func ProvideScheduler(
|
|||||||
executor *Executor,
|
executor *Executor,
|
||||||
mutexManager lock.MutexManager,
|
mutexManager lock.MutexManager,
|
||||||
pubsubService pubsub.PubSub,
|
pubsubService pubsub.PubSub,
|
||||||
config *types.Config,
|
config Config,
|
||||||
) (*Scheduler, error) {
|
) (*Scheduler, error) {
|
||||||
return NewScheduler(
|
return NewScheduler(
|
||||||
store,
|
store,
|
||||||
@ -50,7 +49,7 @@ func ProvideScheduler(
|
|||||||
mutexManager,
|
mutexManager,
|
||||||
pubsubService,
|
pubsubService,
|
||||||
config.InstanceID,
|
config.InstanceID,
|
||||||
config.BackgroundJobs.MaxRunning,
|
config.BackgroundJobsMaxRunning,
|
||||||
config.BackgroundJobs.RetentionTime,
|
config.BackgroundJobsRetentionTime,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user