Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71ba4a9c56 | ||
|
|
8fc4bb7626 |
@@ -14,10 +14,10 @@ jobs:
|
|||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.96.1
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -33,10 +33,10 @@ jobs:
|
|||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.96.1
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
@@ -53,10 +53,10 @@ jobs:
|
|||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.96.1
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
|
|||||||
Generated
+182
-604
File diff suppressed because it is too large
Load Diff
+5
-7
@@ -1,18 +1,16 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "catapult"
|
name = "catapult"
|
||||||
version = "0.3.0"
|
version = "0.3.2"
|
||||||
rust-version = "1.96"
|
rust-version = "1.96.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.52.3", features = ["full"] }
|
tokio = { version = "1.52.3", features = ["full"] }
|
||||||
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_json = { version = "1.0.150" }
|
serde_json = { version = "1.0.150" }
|
||||||
time = { version = "0.3.49", features = ["formatting", "macros", "parsing", "serde"] }
|
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] }
|
||||||
uuid = { version = "1.23.3", features = ["v4", "serde"] }
|
uuid = { version = "1.23.3", features = ["v4", "serde"] }
|
||||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.4.10" }
|
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.5.1" }
|
||||||
swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.4.2.0" }
|
swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.5.2" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Stage 1: Build the application
|
# Stage 1: Build the application
|
||||||
FROM rust:1.96 as builder
|
FROM rust:1.96.1 as builder
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|||||||
+6
-8
@@ -12,14 +12,12 @@ pub struct App {
|
|||||||
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.
|
pub fn load_app() -> Result<App, std::io::Error> {
|
||||||
// Will require changes in other libraries
|
|
||||||
pub async fn load_app() -> Result<App, std::io::Error> {
|
|
||||||
use textsender_models::envy;
|
use textsender_models::envy;
|
||||||
let auth_url_env = envy::environment::get_env("AUTH_URL").await;
|
let auth_url_env = envy::environment::get_env("AUTH_URL");
|
||||||
let api_url_env = envy::environment::get_env("API_URL").await;
|
let api_url_env = envy::environment::get_env("API_URL");
|
||||||
let service_username_env = envy::environment::get_env("SERVICE_USERNAME").await;
|
let service_username_env = envy::environment::get_env("SERVICE_USERNAME");
|
||||||
let service_passphrase_env = envy::environment::get_env("SERVICE_PASSPHRASE").await;
|
let service_passphrase_env = envy::environment::get_env("SERVICE_PASSPHRASE");
|
||||||
|
|
||||||
let envs = vec![
|
let envs = vec![
|
||||||
api_url_env,
|
api_url_env,
|
||||||
@@ -40,7 +38,7 @@ 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() {
|
||||||
Ok(twilio_config) => Ok(App {
|
Ok(twilio_config) => Ok(App {
|
||||||
api_url: envs[0].value.clone(),
|
api_url: envs[0].value.clone(),
|
||||||
auth_url: envs[1].value.clone(),
|
auth_url: envs[1].value.clone(),
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
std::process::exit(-1);
|
std::process::exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let app = match catapult::app::load_app().await {
|
let app = match catapult::app::load_app() {
|
||||||
Ok(app) => app,
|
Ok(app) => app,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
|
|||||||
+12
-28
@@ -5,7 +5,6 @@ pub struct Service {
|
|||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
pub async fn do_the_work(&mut self) {
|
pub async fn do_the_work(&mut self) {
|
||||||
println!("Do some work");
|
|
||||||
println!("Checking queue");
|
println!("Checking queue");
|
||||||
|
|
||||||
use textsender_models::message::scheduling::ScheduledMessage;
|
use textsender_models::message::scheduling::ScheduledMessage;
|
||||||
@@ -69,6 +68,14 @@ impl Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let events = events.unwrap_or_default();
|
let events = events.unwrap_or_default();
|
||||||
|
let mut sendmsg = swoosh::SendMsg::default();
|
||||||
|
sendmsg.load_config(
|
||||||
|
&self.app.twilio_config.auth_token,
|
||||||
|
&self.app.twilio_config.phone_number,
|
||||||
|
&self.app.twilio_config.service_sid,
|
||||||
|
&self.app.twilio_config.account_sid,
|
||||||
|
);
|
||||||
|
|
||||||
for event in &events {
|
for event in &events {
|
||||||
println!("Event: {event:?}");
|
println!("Event: {event:?}");
|
||||||
let contact = &match contacts.get(&event.contact_id).await {
|
let contact = &match contacts.get(&event.contact_id).await {
|
||||||
@@ -105,8 +112,10 @@ impl Service {
|
|||||||
let twilio_config = &self.app.twilio_config;
|
let twilio_config = &self.app.twilio_config;
|
||||||
println!("Config: {twilio_config:?}");
|
println!("Config: {twilio_config:?}");
|
||||||
println!("SM: {scheduled_message:?}");
|
println!("SM: {scheduled_message:?}");
|
||||||
|
sendmsg.load_message(&message.content);
|
||||||
|
sendmsg.load_recipient(&contact.phone_number);
|
||||||
|
|
||||||
match swoosh::twilio::api::send_message(message, contact, ¶m, twilio_config).await {
|
match sendmsg.send_message(¶m).await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
println!("Message scheduled");
|
println!("Message scheduled");
|
||||||
// MER response
|
// MER response
|
||||||
@@ -138,39 +147,14 @@ impl Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
todo!(
|
|
||||||
r#"
|
|
||||||
Need to finish this
|
|
||||||
|
|
||||||
[X] - 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 - Done
|
|
||||||
2. If there is an item, get the data - Done
|
|
||||||
3. Evaluate if it is schedulable - Done
|
|
||||||
4. Get the events and iterate each one - Done
|
|
||||||
5. Starting with the message - Done
|
|
||||||
6. Get the contact - Done
|
|
||||||
7. Send the message
|
|
||||||
8. Record the message event response - Added, not used
|
|
||||||
9. Add to scheduler
|
|
||||||
"#
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_schedulable(
|
fn is_schedulable(
|
||||||
&self,
|
&self,
|
||||||
queue_item: &textsender_models::message::scheduling::ScheduledMessage,
|
queue_item: &textsender_models::message::scheduling::ScheduledMessage,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let now = time::OffsetDateTime::now_utc();
|
|
||||||
|
|
||||||
match queue_item.scheduled {
|
match queue_item.scheduled {
|
||||||
Some(date) => date > now,
|
Some(date) => date > time::OffsetDateTime::now_utc(),
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user