diff options
Diffstat (limited to 'crates/discord-bot/src/jobs.rs')
| -rw-r--r-- | crates/discord-bot/src/jobs.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/discord-bot/src/jobs.rs b/crates/discord-bot/src/jobs.rs index 40d34cc..f35c471 100644 --- a/crates/discord-bot/src/jobs.rs +++ b/crates/discord-bot/src/jobs.rs @@ -1,9 +1,8 @@ -use crate::{config::Config, consts::NIXPKGS_REMOTE, consts::NIXPKGS_URL}; +use crate::config::Config; -use std::{path::Path, time::Duration}; +use std::time::Duration; use eyre::Result; -use git_tracker::ManagedRepository; use log::error; const TTL_SECS: u64 = 60 * 5; // 5 minutes @@ -13,20 +12,19 @@ const TTL_SECS: u64 = 60 * 5; // 5 minutes /// # Errors /// /// Will return [`Err`] if any jobs fail -pub fn dispatch(config: Config) -> Result<()> { - let managed_repository = ManagedRepository { - path: Path::new(&config.nixpkgs_path).to_path_buf(), - tracked_branches: config.nixpkgs_branches, - upstream_remote_url: NIXPKGS_URL.to_string(), - upstream_remote_name: NIXPKGS_REMOTE.to_string(), - }; +pub fn dispatch(config: &Config) -> Result<()> { + let repository = config.repository(); + if repository.open().is_err() { + repository.clone_repository()?; + } + repository.fetch()?; - managed_repository.fetch_or_update()?; + let repository_clone = repository.clone(); tokio::spawn(async move { loop { tokio::time::sleep(Duration::from_secs(TTL_SECS)).await; - if let Err(why) = managed_repository.fetch_or_update() { + if let Err(why) = repository_clone.fetch() { error!("Could not fetch or update repository!\n{why:?}"); }; } |
