-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(callbacks): queued_count and stashed_count callback vars
- Loading branch information
Showing
8 changed files
with
114 additions
and
29 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::fs::read_to_string; | ||
|
||
use anyhow::{Context, Result}; | ||
|
||
use crate::helper::*; | ||
|
||
/// Make sure that callback commands are executed while variables are | ||
/// templated into the command as expected. | ||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_callback_variables() -> Result<()> { | ||
let (mut settings, tempdir) = daemon_base_setup()?; | ||
|
||
// Configure the daemon to use a callback command that echos some variables into a file | ||
// that's located in the temporary runtime directory of the daemon. | ||
let tempdir_path = tempdir.path().to_path_buf(); | ||
let echo_command = | ||
"echo '{{queued_count}}\n{{stashed_count}}\n{{command}}\n{{id}}\n{{result}}'"; | ||
settings.daemon.callback = Some(format!( | ||
"{echo_command} > {}/testfile", | ||
tempdir_path.to_string_lossy() | ||
)); | ||
settings | ||
.save(&Some(tempdir_path.join("pueue.yml"))) | ||
.context("Couldn't write pueue config to temporary directory")?; | ||
|
||
// Create the daemon with the changed settings. | ||
let daemon = daemon_with_settings(settings, tempdir).await?; | ||
let shared = &daemon.settings.shared; | ||
|
||
// Create one stashed task. | ||
assert_success(create_stashed_task(shared, "stashed", None).await?); | ||
// Create a task that'll then trigger the callback | ||
assert_success(add_task(shared, "ls").await?); | ||
|
||
// Give the callback command some time to be executed. | ||
sleep_ms(3000).await; | ||
|
||
let callback_output = read_to_string(tempdir_path.join("testfile"))?; | ||
|
||
assert_eq!(callback_output, "0\n1\nls\n1\nSuccess\n"); | ||
|
||
Ok(()) | ||
} |
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,5 +1,6 @@ | ||
mod add; | ||
mod aliases; | ||
mod callback; | ||
mod clean; | ||
mod edit; | ||
mod environment_variables; | ||
|
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