Change async behaviour of replicate and other commands #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all: Kickass gem, thanks for creating it! I'm surprised this has only 200 stars. You'd think with everyone using SQLite in their new Rails apps a lot more people would use this too 🤷
Anyways. This addresses #42 and some other issues related to running Litestream rake tasks. The existing implementation would run any command as a forked process. This leads to problems when running replication from the command line or through Foreman.
# Forks the process and exits. Troublesome to stop on the command line, screws with Foreman and other process monitors rails litestream:replicate
The way I think about it, there are two types of Litestream commands: short-running ones and long-running ones. The only long-running command is
replicate
. Any other command will exit quickly, whilereplicate
will keep running until terminated.replicate
will be started as a fork or in the same process, depending on the context. Puma will start replication as a forked process, while the rake tasks don't. When running in-process, we capture output continuously and write to stdout.This separation allows for simplification of arguments. We no longer need the
async: true
for short-running commands. Table formatting is also simplified, as most short-running commands output a tabular format. The only exception is the restore command.Short-running commands now always return a hash, which is converted to a tabular output in the Rake task and then printed.
Testing
I gave my fork a go with one of my apps, running the various rake tasks, running in Puma, and so on. Caught a bunch of issues, hopefully got them all.
Other Changes
sqlite3
conflict (?) when trying to run tests 🤷sqlite3
development dependency.If you'd rather have a separate PR for the various little bits let me know, happy to take them out and move to a separate PR.