From 292d0e5de1421091bed592c8935149a7241b539c Mon Sep 17 00:00:00 2001 From: Bittrance Date: Sun, 19 Nov 2023 22:07:00 +0100 Subject: [PATCH] Unwind the task module and return to flat file/module structure. --- src/{task => }/github.rs | 0 src/lib.rs | 11 +++++------ src/main.rs | 4 ++-- src/opts.rs | 8 +++----- src/{task/mod.rs => state.rs} | 17 +---------------- src/store.rs | 5 +---- src/{task/scheduled.rs => task.rs} | 9 ++------- src/testutils.rs | 5 +---- src/{task/gitworkload.rs => workload.rs} | 6 +++++- tests/workload.rs | 2 +- 10 files changed, 21 insertions(+), 46 deletions(-) rename src/{task => }/github.rs (100%) rename src/{task/mod.rs => state.rs} (52%) rename src/{task/scheduled.rs => task.rs} (96%) rename src/{task/gitworkload.rs => workload.rs} (96%) diff --git a/src/task/github.rs b/src/github.rs similarity index 100% rename from src/task/github.rs rename to src/github.rs diff --git a/src/lib.rs b/src/lib.rs index 6f47f19..8a87327 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,18 +1,21 @@ use std::{thread::sleep, time::Duration}; -use task::{scheduled::ScheduledTask, Workload}; +use crate::{task::ScheduledTask, workload::Workload}; pub mod actions; pub mod config; pub mod errors; +pub mod github; pub mod gix; pub mod opts; pub mod receiver; +pub mod state; pub mod store; pub mod task; #[cfg(test)] pub(crate) mod testutils; pub(crate) mod utils; +pub mod workload; #[derive(Debug, PartialEq)] pub enum Progress { @@ -76,11 +79,7 @@ mod lib { use gix::{hash::Kind, ObjectId}; - use crate::{ - errors::GitOpsError, - task::{scheduled::ScheduledTask, State}, - testutils::TestWorkload, - }; + use crate::{errors::GitOpsError, state::State, task::ScheduledTask, testutils::TestWorkload}; #[test] fn run_eligible_task() { diff --git a/src/main.rs b/src/main.rs index 2a089fa..af00cc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ use kitops::errors::GitOpsError; use kitops::opts::{load_store, load_tasks, CliOptions}; use kitops::run_tasks; use kitops::store::Store; -use kitops::task::gitworkload::GitWorkload; -use kitops::task::scheduled::ScheduledTask; +use kitops::task::ScheduledTask; +use kitops::workload::GitWorkload; use std::collections::HashSet; use std::time::Duration; diff --git a/src/opts.rs b/src/opts.rs index df5eee3..5d1944a 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -5,14 +5,12 @@ use clap::Parser; use crate::{ config::{read_config, GitTaskConfig}, errors::GitOpsError, + github::{github_watcher, GithubUrlProvider}, gix::DefaultUrlProvider, receiver::logging_receiver, store::{FileStore, Store}, - task::{ - github::{github_watcher, GithubUrlProvider}, - gitworkload::GitWorkload, - scheduled::ScheduledTask, - }, + task::ScheduledTask, + workload::GitWorkload, }; const DEFAULT_BRANCH: &str = "main"; diff --git a/src/task/mod.rs b/src/state.rs similarity index 52% rename from src/task/mod.rs rename to src/state.rs index f8e5bea..bbc1154 100644 --- a/src/task/mod.rs +++ b/src/state.rs @@ -1,23 +1,8 @@ -use std::{ - path::PathBuf, - time::{Duration, SystemTime}, -}; +use std::time::SystemTime; use gix::{hash::Kind, ObjectId}; use serde::{Deserialize, Serialize}; -use crate::errors::GitOpsError; - -pub mod github; -pub mod gitworkload; -pub mod scheduled; - -pub trait Workload { - fn id(&self) -> String; - fn interval(&self) -> Duration; - fn perform(self, workdir: PathBuf, current_sha: ObjectId) -> Result; -} - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct State { pub next_run: SystemTime, diff --git a/src/store.rs b/src/store.rs index 1879c69..81be62f 100644 --- a/src/store.rs +++ b/src/store.rs @@ -4,10 +4,7 @@ use std::{ path::{Path, PathBuf}, }; -use crate::{ - errors::GitOpsError, - task::{scheduled::ScheduledTask, State, Workload}, -}; +use crate::{errors::GitOpsError, state::State, task::ScheduledTask, workload::Workload}; pub trait Store { fn get(&self, id: &str) -> Option<&State>; diff --git a/src/task/scheduled.rs b/src/task.rs similarity index 96% rename from src/task/scheduled.rs rename to src/task.rs index c6a97f1..25e97cf 100644 --- a/src/task/scheduled.rs +++ b/src/task.rs @@ -6,9 +6,7 @@ use std::{ use gix::ObjectId; -use crate::errors::GitOpsError; - -use super::{State, Workload}; +use crate::{errors::GitOpsError, state::State, workload::Workload}; pub struct ScheduledTask { work: W, @@ -89,10 +87,7 @@ mod tests { use gix::ObjectId; - use crate::{ - task::{scheduled::ScheduledTask, State}, - testutils::TestWorkload, - }; + use crate::{state::State, task::ScheduledTask, testutils::TestWorkload}; #[test] fn scheduled_task_flow() { diff --git a/src/testutils.rs b/src/testutils.rs index cebc105..3dcff37 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -2,10 +2,7 @@ use std::{path::PathBuf, sync::Arc, thread::sleep, time::Duration}; use gix::ObjectId; -use crate::{ - errors::GitOpsError, - task::{scheduled::ScheduledTask, Workload}, -}; +use crate::{errors::GitOpsError, task::ScheduledTask, workload::Workload}; impl ScheduledTask { pub fn await_finished(&self) { diff --git a/src/task/gitworkload.rs b/src/workload.rs similarity index 96% rename from src/task/gitworkload.rs rename to src/workload.rs index 8a75c36..a638cad 100644 --- a/src/task/gitworkload.rs +++ b/src/workload.rs @@ -14,7 +14,11 @@ use crate::{ receiver::WorkloadEvent, }; -use super::Workload; +pub trait Workload { + fn id(&self) -> String; + fn interval(&self) -> Duration; + fn perform(self, workdir: PathBuf, current_sha: ObjectId) -> Result; +} #[allow(clippy::type_complexity)] #[derive(Clone)] diff --git a/tests/workload.rs b/tests/workload.rs index 26ee33c..bd4fcce 100644 --- a/tests/workload.rs +++ b/tests/workload.rs @@ -6,7 +6,7 @@ use kitops::{ errors::GitOpsError, gix::DefaultUrlProvider, receiver::{SourceType, WorkloadEvent}, - task::{gitworkload::GitWorkload, Workload}, + workload::{GitWorkload, Workload}, }; use utils::*;