Skip to content

Conversation

hschne
Copy link
Contributor

@hschne hschne commented May 29, 2025

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, while replicate will keep running until terminated.

  1. Short-running commands never need to be forked. We execute them, capture their output, and return.
  2. 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

  • Had to update to Rails 8 as dev dependency because I got a sqlite3 conflict (?) when trying to run tests 🤷
  • Removed logfmt, because we don't need it anymore (?). Also removed superfluous sqlite3 development dependency.
  • Updated standardrb to minimum Ruby version matching the gemspec
  • Added a small bit to the readme on how to download litestream executables, because that tripped me up.
  • Extracted argument parsing in the rake task

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.

@hschne hschne force-pushed the 25-05-async-commands branch from a8926c1 to 2aec3b1 Compare May 29, 2025 18:42
@hschne hschne force-pushed the 25-05-async-commands branch from 2aec3b1 to c5a557f Compare May 29, 2025 18:43
Copy link
Owner

@fractaledmind fractaledmind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions. I like the idea and certainly want to improve this area, but I don't fully grok everything yet.

@fractaledmind
Copy link
Owner

This feels like it should be a code comment somewhere appropriate:

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.

@hschne
Copy link
Contributor Author

hschne commented Jun 11, 2025

Thanks for the great suggestions! Good call on the comment, moved it to the replicate command method.

I have some questions. I like the idea and certainly want to improve this area, but I don't fully grok everything yet

Sure thing! Let me know how I can help 🙌

@fractaledmind fractaledmind merged commit 7d75863 into fractaledmind:main Jun 13, 2025
11 checks passed
@fractaledmind
Copy link
Owner

Released in v0.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants