Skip to content

Commit

Permalink
Make database open attempts configurable also via config file
Browse files Browse the repository at this point in the history
  • Loading branch information
steinex committed Aug 21, 2019
1 parent 77d7c38 commit 6f9b268
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ func (context *AptlyContext) _database() (database.Storage, error) {
}
}

tries := context.flags.Lookup("db-open-attempts").Value.Get().(int)
var tries int
if context.config().DatabaseOpenAttempts == -1 {
tries = context.flags.Lookup("db-open-attempts").Value.Get().(int)
} else {
tries = context.config().DatabaseOpenAttempts
}

const BaseDelay = 10 * time.Second
const Jitter = 1 * time.Second

Expand Down
5 changes: 5 additions & 0 deletions man/aptly.1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Configuration file is stored in JSON format (default values shown below):
"downloadSpeedLimit": 0,
"downloadRetries": 0,
"architectures": [],
"databaseOpenAttempts": 10,
"dependencyFollowSuggests": false,
"dependencyFollowRecommends": false,
"dependencyFollowAllVariants": false,
Expand Down Expand Up @@ -122,6 +123,10 @@ limit in kbytes/sec on download speed while mirroring remote repositories
number of retries for download attempts
.
.TP
\fBdatabaseOpenAttempts\fR
number of attempts to open DB if it's locked by other instance; could be overridden with option \fB\-db-open-attempts\fR
.
.TP
\fBarchitectures\fR
is a list of architectures to process; if left empty defaults to all available architectures; could be overridden with option \fB\-architectures\fR
.
Expand Down
5 changes: 5 additions & 0 deletions man/aptly.1.ronn.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Configuration file is stored in JSON format (default values shown below):
"downloadConcurrency": 4,
"downloadSpeedLimit": 0,
"downloadRetries": 0,
"databaseOpenAttempts": 10,
"architectures": [],
"dependencyFollowSuggests": false,
"dependencyFollowRecommends": false,
Expand Down Expand Up @@ -105,6 +106,10 @@ Options:
* `downloadRetries`:
number of retries for download attempts

* `databaseOpenAttempts`:
number of attempts to open DB if it's locked by other instance; could be overridden with option
`-db-open-attempts`

* `architectures`:
is a list of architectures to process; if left empty defaults to all available architectures; could be
overridden with option `-architectures`
Expand Down
1 change: 1 addition & 0 deletions system/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class BaseTest(object):
"downloadConcurrency": 4,
"downloadSpeedLimit": 0,
"downloadRetries": 5,
"databaseOpenAttempts": 10,
"architectures": [],
"dependencyFollowSuggests": False,
"dependencyFollowRecommends": False,
Expand Down
1 change: 1 addition & 0 deletions system/t02_config/ConfigShowTest_gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"downloadConcurrency": 4,
"downloadSpeedLimit": 0,
"downloadRetries": 5,
"databaseOpenAttempts": 10,
"architectures": [],
"dependencyFollowSuggests": false,
"dependencyFollowRecommends": false,
Expand Down
3 changes: 2 additions & 1 deletion system/t02_config/CreateConfigTest_gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"downloadConcurrency": 4,
"downloadSpeedLimit": 0,
"downloadRetries": 0,
"databaseOpenAttempts": 10,
"architectures": [],
"dependencyFollowSuggests": false,
"dependencyFollowRecommends": false,
Expand All @@ -20,4 +21,4 @@
"FileSystemPublishEndpoints": {},
"S3PublishEndpoints": {},
"SwiftPublishEndpoints": {}
}
}
3 changes: 2 additions & 1 deletion system/t02_config/aptly.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"rootDir": "/tmp/aptly",
"downloadConcurrency": 4,
"databaseOpenAttempts": 10,
"architectures": [],
"dependencyFollowSuggests": false,
"dependencyFollowRecommends": false,
"dependencyFollowAllVariants": false,
"gpgDisableSign": false,
"gpgDisableVerify": false
}
}
2 changes: 2 additions & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ConfigStructure struct { // nolint: maligned
DownloadConcurrency int `json:"downloadConcurrency"`
DownloadLimit int64 `json:"downloadSpeedLimit"`
DownloadRetries int `json:"downloadRetries"`
DatabaseOpenAttempts int `json:"databaseOpenAttempts"`
Architectures []string `json:"architectures"`
DepFollowSuggests bool `json:"dependencyFollowSuggests"`
DepFollowRecommends bool `json:"dependencyFollowRecommends"`
Expand Down Expand Up @@ -76,6 +77,7 @@ var Config = ConfigStructure{
RootDir: filepath.Join(os.Getenv("HOME"), ".aptly"),
DownloadConcurrency: 4,
DownloadLimit: 0,
DatabaseOpenAttempts: -1,
Architectures: []string{},
DepFollowSuggests: false,
DepFollowRecommends: false,
Expand Down
1 change: 1 addition & 0 deletions utils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (s *ConfigSuite) TestSaveConfig(c *C) {
" \"downloadConcurrency\": 5,\n"+
" \"downloadSpeedLimit\": 0,\n"+
" \"downloadRetries\": 0,\n"+
" \"databaseOpenAttempts\": 10,\n"+
" \"architectures\": null,\n"+
" \"dependencyFollowSuggests\": false,\n"+
" \"dependencyFollowRecommends\": false,\n"+
Expand Down

0 comments on commit 6f9b268

Please sign in to comment.