refactor: optimize imports
This commit is contained in:
parent
25e63c2aae
commit
ea076dcf72
7 changed files with 39 additions and 14 deletions
|
@ -9,3 +9,4 @@ edition = "2021"
|
||||||
simple-log = "1.6.0"
|
simple-log = "1.6.0"
|
||||||
toml = "0.7.3"
|
toml = "0.7.3"
|
||||||
serde = { version = "1.0.162", features = ["derive"] }
|
serde = { version = "1.0.162", features = ["derive"] }
|
||||||
|
thiserror = "1.0.40"
|
|
@ -1,9 +1,5 @@
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::ffmpeg::FFmpegCommandOptions;
|
|
||||||
|
|
||||||
mod ffmpeg;
|
mod ffmpeg;
|
||||||
|
|
||||||
#[allow(non_camel_case_types)] // this is allowed cuz we want to use snake case in the config file
|
#[allow(non_camel_case_types)] // this is allowed cuz we want to use snake case in the config file
|
||||||
|
|
13
src/error.rs
Normal file
13
src/error.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error("Renice error: {0}")]
|
||||||
|
ReniceError(std::io::Error),
|
||||||
|
|
||||||
|
#[error("FFmpeg error: {0}")]
|
||||||
|
FFmpegError(std::io::Error),
|
||||||
|
|
||||||
|
#[error("Job error: {0}")]
|
||||||
|
JobError(std::io::Error),
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use crate::configuration::Config;
|
|
||||||
|
|
||||||
pub fn get_files<S: Into<String>>(path: S) -> Vec<PathBuf> {
|
pub fn get_files<S: Into<String>>(path: S) -> Vec<PathBuf> {
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
|
|
|
@ -3,7 +3,9 @@ extern crate simple_log;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use simple_log::LogConfigBuilder;
|
use simple_log::LogConfigBuilder;
|
||||||
|
|
||||||
use renice::renice;
|
use renice::renice;
|
||||||
use transcode::job::TranscodeJob;
|
use transcode::job::TranscodeJob;
|
||||||
|
|
||||||
|
@ -12,6 +14,7 @@ mod files;
|
||||||
mod ffmpeg;
|
mod ffmpeg;
|
||||||
mod renice;
|
mod renice;
|
||||||
mod transcode;
|
mod transcode;
|
||||||
|
mod error;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let config = configuration::Config::from_file(&env::var("CONFIG").unwrap_or(String::from("./config.toml")));
|
let config = configuration::Config::from_file(&env::var("CONFIG").unwrap_or(String::from("./config.toml")));
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
use std::error::Error;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn renice(pid: u32, niceness: u8) -> Result<(), Box<dyn Error>> {
|
use crate::error;
|
||||||
|
|
||||||
|
pub fn renice(pid: u32, niceness: u8) -> Result<(), error::Error> {
|
||||||
let mut command = Command::new("renice");
|
let mut command = Command::new("renice");
|
||||||
command.arg(niceness.to_string());
|
command.arg(niceness.to_string());
|
||||||
command.arg(pid.to_string());
|
command.arg(pid.to_string());
|
||||||
command.spawn()?;
|
match command.output() {
|
||||||
Ok(())
|
Ok(output) => {
|
||||||
|
if output.status.success() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(error::Error::ReniceError(std::io::Error::new(std::io::ErrorKind::Other, "renice failed")))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => Err(error::Error::ReniceError(e))
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::process::{Child, Command};
|
use std::process::{Child, Command};
|
||||||
use crate::configuration::{Config, ConfigFFmpeg};
|
|
||||||
|
use crate::configuration::ConfigFFmpeg;
|
||||||
|
use crate::error;
|
||||||
|
|
||||||
pub struct TranscodeJob {
|
pub struct TranscodeJob {
|
||||||
pub input: String,
|
pub input: String,
|
||||||
|
@ -26,8 +27,11 @@ impl TranscodeJob {
|
||||||
std::path::Path::new(&self.output).exists()
|
std::path::Path::new(&self.output).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&self, ffmpeg_config: &ConfigFFmpeg) -> Result<Child, std::io::Error> {
|
pub fn run(&self, ffmpeg_config: &ConfigFFmpeg) -> Result<Child, error::Error> {
|
||||||
let mut command = self.build_command(ffmpeg_config);
|
let mut command = self.build_command(ffmpeg_config);
|
||||||
command.spawn()
|
match command.spawn() {
|
||||||
|
Ok(child) => Ok(child),
|
||||||
|
Err(e) => Err(error::Error::JobError(e))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue