Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 6343a3e

Browse files
committed
fixes formatting
1 parent 3186c13 commit 6343a3e

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/daemon.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use super::http;
22
use job_scheduler::Job;
33
use job_scheduler::JobScheduler;
44
use log::{debug, error};
5-
use std::{thread, time};
65
use std::str::FromStr;
6+
use std::{thread, time};
77

8+
use super::db;
89
use super::file;
910
use super::util;
10-
use super::db;
1111

1212
pub fn start() -> anyhow::Result<()> {
1313
db::create_db()?;
@@ -36,7 +36,10 @@ fn schedule_tasks(mut sched: JobScheduler) -> anyhow::Result<JobScheduler> {
3636
let schedule: Vec<db::Schedule> = db::get_schedule()?;
3737
for item in schedule {
3838
match file::create_file_for_user(Some(&item.user)) {
39-
Ok(_) => debug!("authorized keys file for {} exists or was created", &item.user),
39+
Ok(_) => debug!(
40+
"authorized keys file for {} exists or was created",
41+
&item.user
42+
),
4043
Err(e) => {
4144
error!(
4245
"Unable to create authorized keys file for user {}. {}",
@@ -46,9 +49,10 @@ fn schedule_tasks(mut sched: JobScheduler) -> anyhow::Result<JobScheduler> {
4649
}
4750
}
4851

49-
sched.add(Job::new(cron::Schedule::from_str(&item.cron).unwrap(), move || {
50-
run_job(item.user.to_owned(), item.url.to_owned())
51-
}));
52+
sched.add(Job::new(
53+
cron::Schedule::from_str(&item.cron).unwrap(),
54+
move || run_job(item.user.to_owned(), item.url.to_owned()),
55+
));
5256
println!("Scheduled item");
5357
}
5458

@@ -84,4 +88,4 @@ fn run_job(user: String, url: String) {
8488
),
8589
Err(e) => eprint!("failed to write keys to file. {}", e),
8690
};
87-
}
91+
}

src/db.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
use anyhow::anyhow;
2+
use cron;
3+
use log::{info, warn};
14
use rusqlite::NO_PARAMS;
25
use rusqlite::{params, Connection};
3-
use std::path::PathBuf;
46
use std::fs;
5-
use url::Url;
6-
use cron;
7+
use std::path::PathBuf;
78
use std::str::FromStr;
8-
use log::{warn, info};
9-
use anyhow::anyhow;
9+
use url::Url;
1010

1111
use super::file;
1212

@@ -19,7 +19,6 @@ pub struct Schedule {
1919
pub url: String,
2020
}
2121

22-
2322
/// Creates the db and path to it if it doesn't already exist
2423
pub fn create_db() -> anyhow::Result<()> {
2524
let path = file::get_schedule_path();
@@ -32,10 +31,10 @@ pub fn create_db() -> anyhow::Result<()> {
3231
if !parent.is_dir() {
3332
fs::create_dir_all(parent)?;
3433
}
35-
34+
3635
let conn: Connection = Connection::open(path)?;
3736
conn.execute(
38-
"create table if not exists Schedule (
37+
"create table if not exists Schedule (
3938
id integer primary key,
4039
user text not null,
4140
cron text not null,
@@ -51,16 +50,18 @@ pub fn delete_schedule(id: i32) -> anyhow::Result<()> {
5150
let path: PathBuf = file::get_schedule_path();
5251
let conn: Connection = Connection::open(path)?;
5352

54-
conn.execute(
55-
"DELETE FROM Schedule WHERE ID = ?1",
56-
params![id],
57-
)?;
53+
conn.execute("DELETE FROM Schedule WHERE ID = ?1", params![id])?;
5854
Ok(())
5955
}
6056

6157
/// Adds a new schedule to the database
6258
pub fn add_schedule(user: String, cron: String, url: String) -> anyhow::Result<()> {
63-
let schedule: Schedule = validate_schdule(Schedule{id: 0, user, cron, url})?;
59+
let schedule: Schedule = validate_schdule(Schedule {
60+
id: 0,
61+
user,
62+
cron,
63+
url,
64+
})?;
6465

6566
create_db()?;
6667
let path: PathBuf = file::get_schedule_path();
@@ -77,9 +78,9 @@ pub fn add_schedule(user: String, cron: String, url: String) -> anyhow::Result<(
7778
pub fn get_schedule() -> anyhow::Result<Vec<Schedule>> {
7879
let path = file::get_schedule_path();
7980
let conn: Connection = Connection::open(path)?;
80-
81+
8182
let mut stmt = conn.prepare("SELECT id, user, cron, url FROM Schedule")?;
82-
let schedule_iter =stmt.query_map(params![], |row| {
83+
let schedule_iter = stmt.query_map(params![], |row| {
8384
Ok(Schedule {
8485
id: row.get(0)?,
8586
user: row.get(1)?,
@@ -99,14 +100,14 @@ pub fn get_schedule() -> anyhow::Result<Vec<Schedule>> {
99100
Err(e) => warn!("Database has invalid data, {} for ID {}", e, id),
100101
}
101102
}
102-
Err(e) => warn!("Invaid result from database, {}", e)
103+
Err(e) => warn!("Invaid result from database, {}", e),
103104
}
104105
}
105106
Ok(schedules)
106107
}
107108

108109
// Returns a Schedule if its valid, None if its not
109-
fn validate_schdule(schedule: Schedule) -> anyhow::Result<Schedule>{
110+
fn validate_schdule(schedule: Schedule) -> anyhow::Result<Schedule> {
110111
if Url::parse(&schedule.url).is_err() {
111112
return Err(anyhow!("Invalid schedule"));
112113
}

src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ fn jobs() -> anyhow::Result<()> {
301301
if total_jobs > 0 {
302302
println!("{:<5}{:<15}{:<25}{:<45}", "ID", "User", "Cron", "Url");
303303
println!("{:-<90}", "");
304-
for job in jobs {
305-
println!("{:<5}{:<15}{:<25}{:<40}", job.id, job.user, job.cron, job.url);
304+
for job in jobs {
305+
println!(
306+
"{:<5}{:<15}{:<25}{:<40}",
307+
job.id, job.user, job.cron, job.url
308+
);
306309
}
307310
}
308311
Ok(())

0 commit comments

Comments
 (0)