Skip to content

Commit

Permalink
Unwind the task module and return to flat file/module structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
bittrance committed Nov 20, 2023
1 parent befbaf9 commit 292d0e5
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 46 deletions.
File renamed without changes.
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 3 additions & 5 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 1 addition & 16 deletions src/task/mod.rs → src/state.rs
Original file line number Diff line number Diff line change
@@ -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<ObjectId, GitOpsError>;
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct State {
pub next_run: SystemTime,
Expand Down
5 changes: 1 addition & 4 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
9 changes: 2 additions & 7 deletions src/task/scheduled.rs → src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W: Workload + Clone + Send> {
work: W,
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 1 addition & 4 deletions src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<W: Workload + Clone + Send + 'static> ScheduledTask<W> {
pub fn await_finished(&self) {
Expand Down
6 changes: 5 additions & 1 deletion src/task/gitworkload.rs → src/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectId, GitOpsError>;
}

#[allow(clippy::type_complexity)]
#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion tests/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use kitops::{
errors::GitOpsError,
gix::DefaultUrlProvider,
receiver::{SourceType, WorkloadEvent},
task::{gitworkload::GitWorkload, Workload},
workload::{GitWorkload, Workload},
};
use utils::*;

Expand Down

0 comments on commit 292d0e5

Please sign in to comment.