cargo fmt
This commit is contained in:
+21
-21
@@ -1,18 +1,17 @@
|
|||||||
/// Seconds to sleep after finising a task
|
/// Seconds to sleep after finising a task
|
||||||
pub const SECONDS_TO_SLEEP: u64 = 5;
|
pub const SECONDS_TO_SLEEP: u64 = 5;
|
||||||
|
|
||||||
|
|
||||||
pub const APP_NAME: &str = "catapult";
|
pub const APP_NAME: &str = "catapult";
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub api_url: String,
|
pub api_url: String,
|
||||||
pub auth_url: String,
|
pub auth_url: String,
|
||||||
pub service_username: String,
|
pub service_username: String,
|
||||||
pub service_passphrase: String,
|
pub service_passphrase: String,
|
||||||
pub twilio_config: textsender_models::config::auxiliary::TwilioConfig,
|
pub twilio_config: textsender_models::config::auxiliary::TwilioConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Change this to non-async at some point.
|
// TODO: Change this to non-async at some point.
|
||||||
// Will require changes in other libraries
|
// Will require changes in other libraries
|
||||||
pub async fn load_app() -> Result<App, std::io::Error> {
|
pub async fn load_app() -> Result<App, std::io::Error> {
|
||||||
use textsender_models::envy;
|
use textsender_models::envy;
|
||||||
@@ -21,7 +20,12 @@ pub async fn load_app() -> Result<App, std::io::Error> {
|
|||||||
let service_username_env = envy::environment::get_env("SERVICE_USERNAME").await;
|
let service_username_env = envy::environment::get_env("SERVICE_USERNAME").await;
|
||||||
let service_passphrase_env = envy::environment::get_env("SERVICE_PASSPHRASE").await;
|
let service_passphrase_env = envy::environment::get_env("SERVICE_PASSPHRASE").await;
|
||||||
|
|
||||||
let envs = vec![auth_url_env, api_url_env, service_username_env, service_passphrase_env];
|
let envs = vec![
|
||||||
|
auth_url_env,
|
||||||
|
api_url_env,
|
||||||
|
service_username_env,
|
||||||
|
service_passphrase_env,
|
||||||
|
];
|
||||||
|
|
||||||
let check_envs = |vs: &Vec<envy::EnvVar>| -> (bool, Option<String>) {
|
let check_envs = |vs: &Vec<envy::EnvVar>| -> (bool, Option<String>) {
|
||||||
for env in vs {
|
for env in vs {
|
||||||
@@ -33,21 +37,17 @@ pub async fn load_app() -> Result<App, std::io::Error> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (envs_valid, reason) = check_envs(&envs);
|
let (envs_valid, reason) = check_envs(&envs);
|
||||||
|
|
||||||
if envs_valid {
|
if envs_valid {
|
||||||
match textsender_models::config::auxiliary::load_config().await {
|
match textsender_models::config::auxiliary::load_config().await {
|
||||||
Ok(twilio_config) => {
|
Ok(twilio_config) => Ok(App {
|
||||||
Ok(App {
|
api_url: String::new(),
|
||||||
api_url: String::new(),
|
auth_url: String::new(),
|
||||||
auth_url: String::new(),
|
service_username: String::new(),
|
||||||
service_username: String::new(),
|
service_passphrase: String::new(),
|
||||||
service_passphrase: String::new(),
|
twilio_config: twilio_config,
|
||||||
twilio_config: twilio_config
|
}),
|
||||||
})
|
Err(err) => Err(err),
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::other(reason.unwrap()))
|
Err(std::io::Error::other(reason.unwrap()))
|
||||||
|
|||||||
+4
-1
@@ -16,6 +16,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
catapult::service::do_the_work(&app).await;
|
catapult::service::do_the_work(&app).await;
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(catapult::app::SECONDS_TO_SLEEP)).await;
|
tokio::time::sleep(tokio::time::Duration::from_secs(
|
||||||
|
catapult::app::SECONDS_TO_SLEEP,
|
||||||
|
))
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -1,8 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
pub async fn do_the_work(_app: &crate::app::App) {
|
pub async fn do_the_work(_app: &crate::app::App) {
|
||||||
println!("Do some work");
|
println!("Do some work");
|
||||||
todo!(r#"
|
todo!(
|
||||||
|
r#"
|
||||||
Need to finish this
|
Need to finish this
|
||||||
|
|
||||||
This function should fetch a token, check if the token is valid, and obtain a refresh token if
|
This function should fetch a token, check if the token is valid, and obtain a refresh token if
|
||||||
@@ -18,5 +17,6 @@ pub async fn do_the_work(_app: &crate::app::App) {
|
|||||||
6. Get the contact
|
6. Get the contact
|
||||||
7. Send the message
|
7. Send the message
|
||||||
8. Record the message event response
|
8. Record the message event response
|
||||||
"#);
|
"#
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user