diff options
author | dakkar <dakkar@thenautilus.net> | 2022-04-03 14:57:43 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2022-04-03 14:57:43 +0100 |
commit | 86486a56d05f3248159a3841fd1e677f6f67c5c3 (patch) | |
tree | ec19aa619ee1ed414b41128fab9371020e088d2d /lib | |
parent | try to avoid calling `.d` on a non-existent file (diff) | |
download | media-control-86486a56d05f3248159a3841fd1e677f6f67c5c3.tar.gz media-control-86486a56d05f3248159a3841fd1e677f6f67c5c3.tar.bz2 media-control-86486a56d05f3248159a3841fd1e677f6f67c5c3.zip |
auto-retry db queries
might work, might make things worse…
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/MediaControl/DB.rakumod | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/App/MediaControl/DB.rakumod b/lib/App/MediaControl/DB.rakumod index f49cfab..e69efad 100644 --- a/lib/App/MediaControl/DB.rakumod +++ b/lib/App/MediaControl/DB.rakumod @@ -5,14 +5,28 @@ class App::MediaControl::DB { has DB::SQLite $.pool is required; method !db(Callable:D $code) { - my $conn = self.pool.db; - # we need an explicit LEAVE block because on 2021.10, `will - # leave { .finish }` kills precomp - LEAVE { .finish with $conn }; - $conn.begin; - $conn.execute('PRAGMA foreign_keys=true'); - KEEP { .commit with $conn }; - return $code($conn) with $conn; + sub do-it { + my $conn = self.pool.db; + # we need an explicit LEAVE block because on 2021.10, `will + # leave { .finish }` kills precomp + LEAVE { .finish with $conn }; + $conn.begin; + $conn.execute('PRAGMA foreign_keys=true'); + KEEP { .commit with $conn }; + return $code($conn) with $conn; + } + + loop { + CATCH { + when DB::SQLite::Error { + note "DB error: {$_.gist}, retrying"; + sleep 0.5; + redo; + } + } + + return do-it(); + } } method ensure-schema() { |