summaryrefslogtreecommitdiff
path: root/crates/discord-bot/src/jobs.rs
diff options
context:
space:
mode:
authorseth <[email protected]>2024-10-10 07:26:29 -0400
committerGitHub <[email protected]>2024-10-10 07:26:29 -0400
commitc61b701095a1f6b52777d317275f34687e57ee3e (patch)
treee5b1e80fa8040b593aeebb9daf83bcc9d78c6e81 /crates/discord-bot/src/jobs.rs
parent4e1fab6ff1d17a0fff50e1a87af8c0bbe8c075f9 (diff)
rise once again my glorious creation (#51)
* git-tracker: update tips after fetch + cleanup * nix: use nix-filter * ci: cleanup * crates: update * git-tracker: don't spam log while transferring * nix: fix static package eval
Diffstat (limited to 'crates/discord-bot/src/jobs.rs')
-rw-r--r--crates/discord-bot/src/jobs.rs22
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:?}");
};
}