feat: add abstraction around task
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -1,32 +1,33 @@
|
||||
use anyhow::Context;
|
||||
|
||||
use super::task::{IntoTask, Task};
|
||||
|
||||
pub struct Plan {}
|
||||
impl Plan {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub async fn tasks(&self) -> anyhow::Result<Vec<Task>> {
|
||||
Ok(vec![Task::new()])
|
||||
pub async fn tasks(&self) -> anyhow::Result<Vec<impl IntoTask>> {
|
||||
Ok(vec![AptTask::new()])
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Task {}
|
||||
pub struct AptTask {}
|
||||
|
||||
impl Task {
|
||||
impl AptTask {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id(&self) -> String {
|
||||
#[async_trait::async_trait]
|
||||
impl Task for AptTask {
|
||||
fn id(&self) -> String {
|
||||
"apt".into()
|
||||
}
|
||||
|
||||
pub async fn should_run(&self) -> anyhow::Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub async fn execute(&self) -> anyhow::Result<()> {
|
||||
async fn execute(&self) -> anyhow::Result<()> {
|
||||
let mut cmd = tokio::process::Command::new("apt-get");
|
||||
cmd.args(["update", "-q"]);
|
||||
let output = cmd.output().await.context("failed to run apt update")?;
|
||||
|
Reference in New Issue
Block a user