Huh wuh (#7)
Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
@@ -21,6 +21,13 @@ jobs:
|
|||||||
toolchain: 1.96
|
toolchain: 1.96
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
cargo check
|
cargo check
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@@ -34,6 +41,13 @@ jobs:
|
|||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
cargo fmt --all -- --check
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
@@ -47,4 +61,11 @@ jobs:
|
|||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||||
cargo clippy -- -D warnings
|
cargo clippy -- -D warnings
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
|
.env
|
||||||
|
.env.docker
|
||||||
|
.env.local
|
||||||
|
|||||||
Generated
+1340
-7
File diff suppressed because it is too large
Load Diff
@@ -10,5 +10,7 @@ futures = { version = "0.3.32" }
|
|||||||
reqwest = { version = "0.13.4", features = ["json", "stream", "multipart"] }
|
reqwest = { version = "0.13.4", features = ["json", "stream", "multipart"] }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.150" }
|
serde_json = { version = "1.0.150" }
|
||||||
|
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.4.3-29-720f3d8f75-111" }
|
||||||
|
swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.4.1-10-6bdec12084-871" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/// Seconds to sleep after finising a task
|
||||||
|
pub const SECONDS_TO_SLEEP: u64 = 5;
|
||||||
|
|
||||||
|
pub const APP_NAME: &str = "catapult";
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
pub api_url: String,
|
||||||
|
pub auth_url: String,
|
||||||
|
pub service_username: String,
|
||||||
|
pub service_passphrase: String,
|
||||||
|
pub twilio_config: textsender_models::config::auxiliary::TwilioConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Change this to non-async at some point.
|
||||||
|
// Will require changes in other libraries
|
||||||
|
pub async fn load_app() -> Result<App, std::io::Error> {
|
||||||
|
use textsender_models::envy;
|
||||||
|
let auth_url_env = envy::environment::get_env("AUTH_URL").await;
|
||||||
|
let api_url_env = envy::environment::get_env("API_URL").await;
|
||||||
|
let service_username_env = envy::environment::get_env("SERVICE_USERNAME").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 check_envs = |vs: &Vec<envy::EnvVar>| -> (bool, Option<String>) {
|
||||||
|
for env in vs {
|
||||||
|
if env.value.is_empty() {
|
||||||
|
return (false, Some(format!("Key {} is not provided", env.key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(true, None)
|
||||||
|
};
|
||||||
|
|
||||||
|
let (envs_valid, reason) = check_envs(&envs);
|
||||||
|
|
||||||
|
if envs_valid {
|
||||||
|
match textsender_models::config::auxiliary::load_config().await {
|
||||||
|
Ok(twilio_config) => Ok(App {
|
||||||
|
api_url: String::new(),
|
||||||
|
auth_url: String::new(),
|
||||||
|
service_username: String::new(),
|
||||||
|
service_passphrase: String::new(),
|
||||||
|
twilio_config: twilio_config,
|
||||||
|
}),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other(reason.unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,3 @@
|
|||||||
|
pub mod app;
|
||||||
|
pub mod service;
|
||||||
pub mod version;
|
pub mod version;
|
||||||
|
|||||||
+19
-5
@@ -1,10 +1,24 @@
|
|||||||
// TODO: Move this somewhere else
|
|
||||||
pub const SECONDS_TO_SLEEP: u64 = 5;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let args = std::env::args().collect();
|
||||||
|
if catapult::version::contains_version(&args) {
|
||||||
|
catapult::version::print_version();
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let app = match catapult::app::load_app().await {
|
||||||
|
Ok(app) => app,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Do some work");
|
catapult::service::do_the_work(&app).await;
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
|
tokio::time::sleep(tokio::time::Duration::from_secs(
|
||||||
|
catapult::app::SECONDS_TO_SLEEP,
|
||||||
|
))
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
pub async fn do_the_work(_app: &crate::app::App) {
|
||||||
|
println!("Do some work");
|
||||||
|
todo!(
|
||||||
|
r#"
|
||||||
|
Need to finish this
|
||||||
|
|
||||||
|
This function should fetch a token, check if the token is valid, and obtain a refresh token if
|
||||||
|
it has expired.
|
||||||
|
|
||||||
|
Then do the real work.
|
||||||
|
|
||||||
|
1. Check the queue
|
||||||
|
2. If there is an item, get the data,
|
||||||
|
3. Evaluate if it is schedulable
|
||||||
|
4. Get the events and iterate each one
|
||||||
|
5. starting with the message
|
||||||
|
6. Get the contact
|
||||||
|
7. Send the message
|
||||||
|
8. Record the message event response
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user