From 8dd2f0b3f8074652d34fa3a9d9f6f08961e9131b Mon Sep 17 00:00:00 2001 From: Stephen Margheim Date: Thu, 22 Aug 2024 23:07:06 +0200 Subject: [PATCH 1/4] Add a verification job --- app/jobs/litestream/verification_job.rb | 11 +++++++++++ lib/litestream.rb | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 app/jobs/litestream/verification_job.rb diff --git a/app/jobs/litestream/verification_job.rb b/app/jobs/litestream/verification_job.rb new file mode 100644 index 0000000..3d1bc79 --- /dev/null +++ b/app/jobs/litestream/verification_job.rb @@ -0,0 +1,11 @@ +module Litestream + class VerificationJob < ApplicationJob + queue_as Litestream.queue + + def perform + Litestream::Commands.databases.each do |db_hash| + Litestream.verify!(db_hash["path"]) + end + end + end +end diff --git a/lib/litestream.rb b/lib/litestream.rb index 8f0dceb..fc703b3 100644 --- a/lib/litestream.rb +++ b/lib/litestream.rb @@ -23,6 +23,7 @@ def initialize mattr_writer :username mattr_writer :password + mattr_writer :queue class << self def verify!(database_path) @@ -60,6 +61,10 @@ def password @password ||= ENV["LITESTREAM_PASSWORD"] || @@password end + def queue + @queue ||= ENV["LITESTREAM_QUEUE"] || @@queue || "default" + end + def replicate_process info = {} if !`which systemctl`.empty? From cd2e5688079affe29b97e08029fe43c5bee353ea Mon Sep 17 00:00:00 2001 From: Stephen Margheim Date: Thu, 22 Aug 2024 23:18:14 +0200 Subject: [PATCH 2/4] Use activejob base --- app/jobs/litestream/verification_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/litestream/verification_job.rb b/app/jobs/litestream/verification_job.rb index 3d1bc79..bdc576e 100644 --- a/app/jobs/litestream/verification_job.rb +++ b/app/jobs/litestream/verification_job.rb @@ -1,5 +1,5 @@ module Litestream - class VerificationJob < ApplicationJob + class VerificationJob < ActiveJob::Base queue_as Litestream.queue def perform From be1483d0f48946aa1e02aa2c63f915af3e868475 Mon Sep 17 00:00:00 2001 From: Stephen Margheim Date: Thu, 22 Aug 2024 23:21:38 +0200 Subject: [PATCH 3/4] Add active_job as a dep --- Gemfile.lock | 1 + app/jobs/litestream/verification_job.rb | 2 ++ litestream.gemspec | 1 + 3 files changed, 4 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 15b2922..abe3471 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: litestream (0.10.5) + activejob logfmt (>= 0.0.10) sqlite3 diff --git a/app/jobs/litestream/verification_job.rb b/app/jobs/litestream/verification_job.rb index bdc576e..50cd81f 100644 --- a/app/jobs/litestream/verification_job.rb +++ b/app/jobs/litestream/verification_job.rb @@ -1,3 +1,5 @@ +require "active_job/base" + module Litestream class VerificationJob < ActiveJob::Base queue_as Litestream.queue diff --git a/litestream.gemspec b/litestream.gemspec index 9001153..ff0f291 100644 --- a/litestream.gemspec +++ b/litestream.gemspec @@ -27,6 +27,7 @@ Gem::Specification.new do |spec| # Uncomment to register a new dependency of your gem spec.add_dependency "logfmt", ">= 0.0.10" spec.add_dependency "sqlite3" + spec.add_dependency "activejob" spec.add_development_dependency "rubyzip" spec.add_development_dependency "rails" spec.add_development_dependency "sqlite3" From 87c9bd1887de8db064e0725d3c37df846a21b960 Mon Sep 17 00:00:00 2001 From: Stephen Margheim Date: Thu, 22 Aug 2024 23:24:24 +0200 Subject: [PATCH 4/4] Require all of active_job --- app/jobs/litestream/verification_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/litestream/verification_job.rb b/app/jobs/litestream/verification_job.rb index 50cd81f..2b32142 100644 --- a/app/jobs/litestream/verification_job.rb +++ b/app/jobs/litestream/verification_job.rb @@ -1,4 +1,4 @@ -require "active_job/base" +require "active_job" module Litestream class VerificationJob < ActiveJob::Base