Retry access in case the settings database is locked
Create `settings::_safer_query` class proc to allow 5 tries with 1s delay; use it for `_nval_setting` and `_tval_setting` methods
This commit is contained in:
parent
567d142613
commit
67e71691eb
@ -54,6 +54,21 @@ class settings {
|
||||
rtschedule 0
|
||||
}
|
||||
|
||||
proc {settings _safer_query} { queryText args } {
|
||||
global settingsdb
|
||||
# allow 5 (too many?) tries with 1s (too long?) delay to get access
|
||||
for {set lockCnt 5} {} {sleep 1} {
|
||||
try {
|
||||
$settingsdb query $queryText {*}$args
|
||||
} on error {msg opts} {
|
||||
if {[string first "database is locked" $msg] >= 0 && [incr lockCnt -1] > 0} {
|
||||
continue
|
||||
}
|
||||
return {*}$opts $msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
settings method hostname {{name ""}} {
|
||||
if {$name == ""} {
|
||||
# Get
|
||||
@ -104,11 +119,10 @@ settings method smtp_server {{server ""}} {
|
||||
}
|
||||
|
||||
settings method _nval_setting {name {val -1}} {
|
||||
global settingsdb
|
||||
|
||||
if {$val == -1} {
|
||||
# Get
|
||||
set res [$settingsdb query "
|
||||
set res [settings::_safer_query "
|
||||
select nval from settings
|
||||
where name = '$name'
|
||||
"]
|
||||
@ -118,7 +132,7 @@ settings method _nval_setting {name {val -1}} {
|
||||
return 0
|
||||
} else {
|
||||
# Set
|
||||
$settingsdb query "
|
||||
settings::_safer_query "
|
||||
replace into settings(name,nval)
|
||||
values('$name', $val)
|
||||
"
|
||||
@ -127,11 +141,10 @@ settings method _nval_setting {name {val -1}} {
|
||||
}
|
||||
|
||||
settings method _tval_setting {name {val -1} {def 0}} {
|
||||
global settingsdb
|
||||
|
||||
if {$val eq "-1"} {
|
||||
# Get
|
||||
set res [$settingsdb query "
|
||||
set res [settings::_safer_query "
|
||||
select tval from settings
|
||||
where name = '$name'
|
||||
"]
|
||||
@ -141,7 +154,7 @@ settings method _tval_setting {name {val -1} {def 0}} {
|
||||
return $def
|
||||
} else {
|
||||
# Set
|
||||
$settingsdb query "
|
||||
settings::_safer_query "
|
||||
replace into settings(name,tval)
|
||||
values('$name', '%s')
|
||||
" $val
|
||||
|
Loading…
Reference in New Issue
Block a user