Skip to content

Commit

Permalink
wip: refresh every hour
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Jun 8, 2024
1 parent ca5dbf2 commit f10d412
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tempfile = "3.10.1"
rust-embed = { version = "8.4.0", features = ["axum", "debug-embed"] }
mime_guess = "2.0.4"
chrono = "0.4.38"
tokio_schedule = "0.3.1"

[features]
monero = ["dep:monero-rpc"]
19 changes: 17 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use crate::repo::TurbineRepo;
use anyhow::Result;
use axum::{
extract::FromRef,
routing::{get, post},
Router,
};
use chrono::Utc;
use clap::{Args, Parser};
use std::{env, process::ExitCode, sync::Arc};
use tokio::spawn;
use tokio::{net::TcpListener, sync::Mutex};
use tokio_schedule::{every, Job};
use tracing::info;

use crate::repo::TurbineRepo;

#[derive(clap::Subcommand, Debug, Clone)]
pub enum Commands {
Serve(ServeArgs),
Expand Down Expand Up @@ -73,6 +74,20 @@ pub async fn serve(args: &ServeArgs) -> Result<ExitCode> {
.route("/refresh", post(crate::api::refresh))
.route("/assets/*file", get(crate::api::assets));

// Refresh every hour
let every_hour = every(1)
.hour()
.at(10, 30)
.in_timezone(&Utc)
.perform(|| async {
reqwest::Client::new()
.post("http://127.0.0.1:3000/refresh")
.send()
.await
.unwrap();
});
tokio::spawn(every_hour);

info!("Starting listener");
let listener =
TcpListener::bind(args.bind.as_ref().unwrap_or(&"0.0.0.0:3000".to_string())).await?;
Expand Down
8 changes: 6 additions & 2 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub struct Contributor {

impl Contributor {
pub fn compute_payout(&self, commit_id: Oid) -> u64 {
todo!()
// TODO
1
}
}

Expand Down Expand Up @@ -88,7 +89,10 @@ impl TurbineRepo {

pub fn refresh(&mut self) -> Result<()> {
// Always fetch the repo first
// TODO
debug!("Fetching upstream repo");
self.container
.find_remote("origin")?
.fetch(&[self.branch.clone()], None, None)?;

let mut revwalk = self.container.revwalk()?;
revwalk.set_sorting(Sort::REVERSE)?;
Expand Down

0 comments on commit f10d412

Please sign in to comment.