feature: Reducing the downtime of a long-running process
Hi, I work on a web application written in Rust.
I use bacon as a watcher to restart automatically the backend server whenever I make a change. Here’s my current bacon.toml file:
default_job = "check"
[jobs.check]
command = ["cargo", "check"]
need_stdout = false
[jobs.run]
command = [
"cargo", "run", "server"
]
need_stdout = true
allow_warnings = true
background = false
on_change_strategy = "kill_then_restart"
watch = ["templates/"]
Compiling my project takes about 5s. When I edit an HTML file in the templates directory (these files are embedded in the rust binary using askama) and save it, bacon triggers a rebuild and restart. The process looks like this:
I’d like to reduce the downtime of my Rust binary during this process. Ideally, it would work more like this:
I tried using the wait_and_restart strategy, but the server never restarts. I’m not very familiar with bacon, so I might be missing something in the configuration.
Any help would be appreciated! Thanks in advance.
The way bacon works for "run" tasks, is it calls the cargo run command.
What you want is to have first the cargo build watched and when it passes without error, the cargo run command be executed.
We may have everything necessary: we can define 2 jobs "build-before-run" and "just-run" and set on_success = job:just-run on the first one.
If I understand correctly:
default_job = "check"
[jobs.check]
command = ["cargo", "check"]
need_stdout = false
[jobs.build]
command = ["cargo", "build"]
need_stdout = true
allow_warnings = true
watch = ["templates/"]
on_success = "job:run"
[jobs.run]
command = [
"cargo", "run", "server"
]
need_stdout = true
background = false
then I run bacon build. It builds then runs the server.
But if I edit a file, the jobs:build is not triggered anymore and the jobs:run is not re-run. I tried different configurations but not luck.
It looks like I have the same issue as https://github.com/Canop/bacon/issues/165#issuecomment-2419956501. From what I understand bacon,
I don't think it is possible to have this kind of workflow so far, let me know If I'm wrong:
I think you're right. I'll have to look for a solution.