summaryrefslogtreecommitdiff
path: root/crates/bot-jobs/src/lib.rs
blob: d65c92955e5606c2930d69ad73baf42072c0bb6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use bot_config::Config;
use bot_error::Error;

use std::time::Duration;

use log::error;

mod repo;

/// Run our jobs an initial time, then loop them on a separate thread
///
/// # Errors
///
/// Will return [`Err`] if any jobs fail
pub fn dispatch(config: Config) -> Result<(), Error> {
	repo::fetch_or_update_repository(&config.nixpkgs_path, &config.nixpkgs_branches)?;

	tokio::spawn(async move {
		loop {
			tokio::time::sleep(Duration::from_secs(repo::TTL_SECS)).await;
			if let Err(why) =
				repo::fetch_or_update_repository(&config.nixpkgs_path, &config.nixpkgs_branches)
			{
				error!("Failed to fetch or update repository!\n{why:?}");
			};
		}
	});

	Ok(())
}