Skip to content

Commit

Permalink
Merge branch 'alpha' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tcheronneau committed Dec 4, 2024
2 parents f6c377a + 472d79d commit 15c1f75
Show file tree
Hide file tree
Showing 14 changed files with 617 additions and 420 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "homers"
version = "0.4.2"
version = "0.5.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.79"
async-trait = "0.1.83"
chrono = "0.4.34"
clap = "4.5.1"
clap-verbosity-flag = "2.2.0"
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ RUN USER=root cargo new homers
WORKDIR /usr/src/homers
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN cargo build --release

RUN cargo install --path .
RUN cargo install --locked --path .

# Bundle Stage
FROM debian:trixie-slim
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vars:
tasks:
build:
cmds:
- cmd: docker build -t mcth/homers:{{.DOCKER_TAG}} .
- cmd: docker buildx build --push --platform linux/amd64 -t mcth/homers:{{.DOCKER_TAG}} .
push:
cmds:
- cmd: docker push mcth/homers:{{.DOCKER_TAG}}
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
rustc
cargo
rustfmt
];
]++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ];
};
});
}
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub enum Task {
TautulliLibrary(Tautulli),
PlexSession(Plex),
PlexLibrary(Plex),
JellyfinSession(Jellyfin),
JellyfinLibrary(Jellyfin),
Default,
}

Expand Down Expand Up @@ -123,5 +125,12 @@ pub fn get_tasks(config: Config) -> anyhow::Result<Vec<Task>> {
tasks.push(Task::PlexLibrary(client));
}
}
if let Some(jellyfin) = config.jellyfin {
for (name, j) in jellyfin {
let client = Jellyfin::new(&name, remove_trailing_slash(&j.address), &j.api_key)?;
tasks.push(Task::JellyfinSession(client.clone()));
tasks.push(Task::JellyfinLibrary(client));
}
}
Ok(tasks)
}
48 changes: 13 additions & 35 deletions src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use futures::future::try_join_all;
use log::{error, info};
use rocket::http::{Accept, ContentType, Status};
use rocket::tokio::task;
use rocket::tokio::task::JoinSet;
use rocket::{get, routes, Build, Responder, Rocket, State};
use std::collections::HashMap;
use std::process::exit;
Expand Down Expand Up @@ -113,6 +112,19 @@ async fn process_tasks(tasks: Vec<Task>) -> Result<Vec<TaskResult>, JoinError> {
let result = HashMap::from([(name.to_string(), result)]);
Ok(TaskResult::PlexLibrary(result))
}
Task::JellyfinSession(jellyfin) => {
let name = &jellyfin.name;
let result = jellyfin.get_current_sessions().await;
let result = HashMap::from([(name.to_string(), result)]);
let users = jellyfin.get_users().await;
Ok(TaskResult::JellyfinSession(result, users))
}
Task::JellyfinLibrary(jellyfin) => {
let name = &jellyfin.name;
let result = jellyfin.get_library().await;
let result = HashMap::from([(name.to_string(), result)]);
Ok(TaskResult::JellyfinLibrary(result))
}
Task::Default => Ok(TaskResult::Default),
}
})
Expand Down Expand Up @@ -142,40 +154,6 @@ async fn serve_metrics(format: Format, unscheduled_tasks: &State<Vec<Task>>) ->
)
}
}
//let mut join_set = JoinSet::new();
//for task in unscheduled_tasks.iter().cloned() {
// join_set.spawn(process_task(task));
//}

//wait_for_metrics(format, join_set).await.map_or_else(
// |e| {
// error!("General error while fetching providers data: {e}");
// MetricsResponse::new(
// Status::InternalServerError,
// format,
// "Error while fetching providers data. Check the logs".into(),
// )
// },
// |metrics| MetricsResponse::new(Status::Ok, format, metrics),
//)
}

async fn wait_for_metrics(
_format: Format,
mut join_set: JoinSet<Result<TaskResult, JoinError>>,
) -> anyhow::Result<String> {
let mut tasks: Vec<TaskResult> = Vec::new();
while let Some(result) = join_set.join_next().await {
match result? {
Ok(tr) => {
tasks.push(tr);
}
Err(e) => {
error!("Error while fetching metrics: {e}");
}
}
}
format_metrics(tasks)
}

const fn get_content_type_params(version: &str) -> [(&str, &str); 2] {
Expand Down
30 changes: 16 additions & 14 deletions src/main.rs.test
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ async fn main() -> Result<()> {
.log_level()
.expect("Log level cannot be not available");
let config = config::read(args.config.clone(), log_level)?;
//let jelly_conf = config.jellyfin.expect("Jellyfin config not found");
//for (name, j) in jelly_conf {
// let jellyfin = Jellyfin::new(&name, &j.address, &j.api_key)?;
// let session = jellyfin.get_sessions().await?;
// println!("{:?}", session);
//}

let plex = config.plex.expect("plex config not found");
for (name, p) in plex {
let plex = providers::plex::Plex::new(&name, &p.address, &p.token)?;
let users = plex.get_users().await;
for user in users {
println!("{:?}", user);
}
let jelly_conf = config.jellyfin.expect("Jellyfin config not found");
for (name, j) in jelly_conf {
let jellyfin = Jellyfin::new(&name, &j.address, &j.api_key)?;
let session = jellyfin.get_sessions().await?;
println!("{:?}", session);
let library_counts = jellyfin.get_library_counts().await?;
println!("{:?}", library_counts);
}

//let plex = config.plex.expect("plex config not found");
//for (name, p) in plex {
// let plex = providers::plex::Plex::new(&name, &p.address, &p.token)?;
// let users = plex.get_users().await;
// for user in users {
// println!("{:?}", user);
// }
//}
// let history = match plex.get_history().await {
// Ok(history) => history,
// Err(e) => {
Expand Down
Loading

0 comments on commit 15c1f75

Please sign in to comment.