Skip to content

Commit 305269a

Browse files
Merge pull request #59 from spinosa/main
configurable sleep time for Litestream.verify!
2 parents ae16087 + 1a3e8e9 commit 305269a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Rails.application.configure do
106106
end
107107
```
108108

109-
However, if you need manual control over the Litestream configuration, you can manually edit the `config/litestream.yml` file. The full range of possible configurations are covered in Litestream's [configuration reference](https://litestream.io/reference/config/).
109+
However, if you need manual control over the Litestream configuration, you can manually edit the `config/litestream.yml` file. The full range of possible configurations are covered in Litestream's [configuration reference](https://litestream.io/reference/config/). NB: If you configure a longer `sync-interval`, you may need to adjust `replication_sleep` when calling `Litestream.verify!`.
110110

111111
### Replication
112112

@@ -221,7 +221,7 @@ You can verify the integrity of your backed-up databases using the gem's provide
221221
Litestream.verify! "storage/production.sqlite3"
222222
```
223223

224-
In order to verify that the backup for that database is both restorable and fresh, the method will add a new row to that database under the `_litestream_verification` table, which it will create if needed. It will then wait 10 seconds to give the Litestream utility time to replicate that change to whatever storage providers you have configured. After that, it will download the latest backup from that storage provider and ensure that this verification row is present in the backup. If the verification row is _not_ present, the method will raise a `Litestream::VerificationFailure` exception. This check ensures that the restored database file:
224+
In order to verify that the backup for that database is both restorable and fresh, the method will add a new row to that database under the `_litestream_verification` table, which it will create if needed. It will then wait `replication_sleep` seconds (defaults to 10) to give the Litestream utility time to replicate that change to whatever storage providers you have configured. After that, it will download the latest backup from that storage provider and ensure that this verification row is present in the backup. If the verification row is _not_ present, the method will raise a `Litestream::VerificationFailure` exception. This check ensures that the restored database file:
225225

226226
1. exists,
227227
2. can be opened by SQLite, and

lib/litestream.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def initialize
3838
mattr_accessor :base_controller_class, default: "::ApplicationController"
3939

4040
class << self
41-
def verify!(database_path)
41+
def verify!(database_path, replication_sleep: 10)
4242
database = SQLite3::Database.new(database_path)
4343
database.execute("CREATE TABLE IF NOT EXISTS _litestream_verification (id INTEGER PRIMARY KEY, uuid BLOB)")
4444
sentinel = SecureRandom.uuid
4545
database.execute("INSERT INTO _litestream_verification (uuid) VALUES (?)", [sentinel])
4646
# give the Litestream replication process time to replicate the sentinel value
47-
sleep 10
47+
sleep replication_sleep
4848

4949
backup_path = "tmp/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{sentinel}.sqlite3"
5050
Litestream::Commands.restore(database_path, **{"-o" => backup_path})

0 commit comments

Comments
 (0)