-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
173 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
# `pitchfork wait` | ||
|
||
- **Usage**: `pitchfork wait` | ||
- **Usage**: `pitchfork wait <ID>` | ||
- **Aliases**: `w` | ||
|
||
Wait for a daemon to stop, tailing the logs along the way | ||
|
||
Exits with the same status code as the daemon | ||
|
||
## Arguments | ||
|
||
### `<ID>` | ||
|
||
The name of the daemon to wait for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
use crate::cli::logs; | ||
use crate::procs::Procs; | ||
use crate::state_file::StateFile; | ||
use crate::Result; | ||
use tokio::time; | ||
|
||
/// Wait for a daemon to stop, tailing the logs along the way | ||
/// | ||
/// Exits with the same status code as the daemon | ||
#[derive(Debug, clap::Args)] | ||
#[clap(visible_alias = "w", verbatim_doc_comment)] | ||
pub struct Wait {} | ||
pub struct Wait { | ||
/// The name of the daemon to wait for | ||
id: String, | ||
} | ||
|
||
impl Wait { | ||
pub async fn run(&self) -> Result<()> { | ||
let sf = StateFile::get(); | ||
let pid = if let Some(pid) = sf.daemons.get(&self.id).and_then(|d| d.pid) { | ||
pid | ||
} else { | ||
warn!("{} is not running", self.id); | ||
return Ok(()); | ||
}; | ||
|
||
let tail_names = vec![self.id.to_string()]; | ||
tokio::spawn(async move { | ||
logs::tail_logs(&tail_names).await.unwrap_or_default(); | ||
}); | ||
|
||
let mut procs = Procs::new(); | ||
let mut interval = time::interval(time::Duration::from_millis(100)); | ||
loop { | ||
if procs.get_process(pid).is_none() { | ||
break; | ||
} | ||
interval.tick().await; | ||
procs.refresh_processes(); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.