-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add housekeeping project fetch size option to the CLI flag
* set project fetch size to 100 in config.sample.yml
- Loading branch information
Showing
6 changed files
with
120 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2023 The Yorkie Authors. All rights reserved. | ||
* | ||
* 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 housekeeping | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// Config is the configuration for the housekeeping service. | ||
type Config struct { | ||
// Interval is the time between housekeeping runs. | ||
Interval string `yaml:"Interval"` | ||
|
||
// CandidatesLimitPerProject is the maximum number of candidates to be returned per project. | ||
CandidatesLimitPerProject int `yaml:"CandidatesLimitPerProject"` | ||
|
||
// HousekeepingProjectFetchSize is the maximum number of projects to be returned to deactivate candidates. | ||
HousekeepingProjectFetchSize int `yaml:"HousekeepingProjectFetchSize"` | ||
} | ||
|
||
// Validate validates the configuration. | ||
func (c *Config) Validate() error { | ||
if _, err := time.ParseDuration(c.Interval); err != nil { | ||
return fmt.Errorf( | ||
`invalid argument %s for "--housekeeping-interval" flag: %w`, | ||
c.Interval, | ||
err, | ||
) | ||
} | ||
|
||
if c.CandidatesLimitPerProject <= 0 { | ||
return fmt.Errorf( | ||
`invalid argument %d for "--housekeeping-candidates-limit-per-project" flag`, | ||
c.HousekeepingProjectFetchSize, | ||
) | ||
} | ||
|
||
if c.HousekeepingProjectFetchSize <= 0 { | ||
return fmt.Errorf( | ||
`invalid argument %d for "--housekeeping-project-fetc-size" flag`, | ||
c.HousekeepingProjectFetchSize, | ||
) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2023 The Yorkie Authors. All rights reserved. | ||
* | ||
* 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 housekeeping_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/yorkie-team/yorkie/server/backend/housekeeping" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
t.Run("validate test", func(t *testing.T) { | ||
validConf := housekeeping.Config{ | ||
Interval: "1m", | ||
CandidatesLimitPerProject: 100, | ||
HousekeepingProjectFetchSize: 100, | ||
} | ||
assert.NoError(t, validConf.Validate()) | ||
|
||
conf1 := validConf | ||
conf1.Interval = "hour" | ||
assert.Error(t, conf1.Validate()) | ||
|
||
conf2 := validConf | ||
conf2.CandidatesLimitPerProject = 0 | ||
assert.Error(t, conf2.Validate()) | ||
|
||
conf3 := validConf | ||
conf3.HousekeepingProjectFetchSize = -1 | ||
assert.Error(t, conf3.Validate()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters