feat: add abstraction around task
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-12-01 14:25:24 +01:00
parent 974e1ee0d6
commit d6fdda0e4e
4 changed files with 67 additions and 12 deletions

View File

@@ -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")?;