-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agent): add a debug agent (#28)
* feat: rework branch with every changes Signed-off-by: ESPIE <[email protected]> * chore: fmt Signed-off-by: ESPIE <[email protected]> --------- Signed-off-by: ESPIE <[email protected]>
- Loading branch information
1 parent
f176aa8
commit e3bd31d
Showing
4 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use super::AgentOutput; | ||
use crate::agents::Agent; | ||
use crate::{workload, AgentResult}; | ||
use std::fs::create_dir_all; | ||
use std::time::SystemTime; | ||
|
||
pub struct DebugAgent { | ||
workload_config: workload::config::Config, | ||
} | ||
|
||
impl From<workload::config::Config> for DebugAgent { | ||
fn from(workload_config: workload::config::Config) -> Self { | ||
Self { workload_config } | ||
} | ||
} | ||
|
||
impl Agent for DebugAgent { | ||
fn prepare(&self) -> AgentResult<AgentOutput> { | ||
let dir = format!("/tmp/{}", self.workload_config.workload_name); | ||
|
||
println!("Function directory: {}", dir); | ||
|
||
create_dir_all(&dir).expect("Unable to create directory"); | ||
|
||
std::fs::write( | ||
format!("{}/debug.txt", &dir), | ||
format!( | ||
"Debug agent for {} - written at {:?}", | ||
self.workload_config.workload_name, | ||
SystemTime::now(), | ||
), | ||
) | ||
.expect("Unable to write debug.txt file"); | ||
|
||
Ok(AgentOutput { | ||
exit_code: 0, | ||
stdout: "Build successfully!".into(), | ||
stderr: String::default(), | ||
}) | ||
} | ||
|
||
fn run(&self) -> AgentResult<AgentOutput> { | ||
let dir = format!("/tmp/{}", self.workload_config.workload_name); | ||
|
||
let content = std::fs::read_to_string(format!("{}/debug.txt", &dir)) | ||
.expect("Unable to read debug.txt file"); | ||
|
||
std::fs::remove_dir_all(dir).expect("Unable to remove directory"); | ||
|
||
Ok(AgentOutput { | ||
exit_code: 0, | ||
stdout: content, | ||
stderr: String::default(), | ||
}) | ||
} | ||
} |
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