Huh wuh #7

Merged
phoenix merged 7 commits from huh_wuh into v0.3.0 2026-06-21 22:48:09 -04:00
8 changed files with 1464 additions and 12 deletions
+21
View File
@@ -21,6 +21,13 @@ jobs:
toolchain: 1.96
- uses: Swatinem/rust-cache@v2
- 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
fmt:
@@ -34,6 +41,13 @@ jobs:
- run: rustup component add rustfmt
- uses: Swatinem/rust-cache@v2
- 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
clippy:
@@ -47,4 +61,11 @@ jobs:
- run: rustup component add clippy
- uses: Swatinem/rust-cache@v2
- 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
+3
View File
@@ -1 +1,4 @@
/target
.env
.env.docker
.env.local
Generated
+1340 -7
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -10,5 +10,7 @@ futures = { version = "0.3.32" }
reqwest = { version = "0.13.4", features = ["json", "stream", "multipart"] }
serde = { version = "1.0.228", features = ["derive"] }
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]
+55
View File
@@ -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()))
}
}
+2
View File
@@ -1 +1,3 @@
pub mod app;
pub mod service;
pub mod version;
+19 -5
View File
@@ -1,10 +1,24 @@
// TODO: Move this somewhere else
pub const SECONDS_TO_SLEEP: u64 = 5;
#[tokio::main]
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 {
println!("Do some work");
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
catapult::service::do_the_work(&app).await;
tokio::time::sleep(tokio::time::Duration::from_secs(
catapult::app::SECONDS_TO_SLEEP,
))
.await;
}
}
+22
View File
@@ -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
"#
);
}