Skip to content

Commit

Permalink
more verbose status logging
Browse files Browse the repository at this point in the history
  • Loading branch information
manglemix committed Jan 15, 2025
1 parent a88460e commit 572b7e6
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 145 deletions.
12 changes: 12 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tasks.web]
workspace = false
cwd = "usr-web"
script_runner = "@shell"
script = '''
npm run dev -- -- --host
'''

[tasks.backend]
workspace = false
command = "cargo"
args = ["run", "-p", "usr-backend"]
49 changes: 40 additions & 9 deletions usr-backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ impl Write for LogWriter {

#[derive(Deserialize)]
struct Config {
new_orders_webhook: String,
order_updates_webhook: String,
new_orders_webhook: Option<String>,
order_updates_webhook: Option<String>,
}

struct UsrState {
db: DatabaseConnection,
new_orders_webhook: DiscordWebhook,
order_updates_webhook: DiscordWebhook,
new_orders_webhook: Option<DiscordWebhook>,
order_updates_webhook: Option<DiscordWebhook>,
}

#[tokio::main]
Expand Down Expand Up @@ -84,10 +84,29 @@ async fn main() -> anyhow::Result<()> {

if Path::new(".reset-db").exists() {
info!("Resetting DB");
let directive = std::fs::read_to_string(".reset-db")?;

match directive.as_str() {
"scheduler" => {
scheduler::reset_tables(&db).await?;
info!("Reset scheduler tables");
}
"manifest" => {
manifest::reset_tables(&db).await?;
info!("Reset manifest tables");
}
"all" => {
scheduler::reset_tables(&db).await?;
manifest::reset_tables(&db).await?;
info!("Reset all tables");
}
_ => {
error!("Invalid directive in .reset-db");
return Ok(());
}
}

std::fs::remove_file(".reset-db")?;
scheduler::reset_tables(&db).await?;
manifest::reset_tables(&db).await?;
info!("DB Reset");
}

let app = Router::new()
Expand Down Expand Up @@ -123,8 +142,20 @@ async fn main() -> anyhow::Result<()> {
)
.with_state(Arc::new(UsrState {
db,
new_orders_webhook: DiscordWebhook::new(config.new_orders_webhook)?,
order_updates_webhook: DiscordWebhook::new(config.order_updates_webhook)?,
new_orders_webhook: {
if let Some(new_orders_webhook) = config.new_orders_webhook {
Some(DiscordWebhook::new(new_orders_webhook)?)
} else {
None
}
},
order_updates_webhook: {
if let Some(order_updates_webhook) = config.order_updates_webhook {
Some(DiscordWebhook::new(order_updates_webhook)?)
} else {
None
}
},
}));

default_provider()
Expand Down
Loading

0 comments on commit 572b7e6

Please sign in to comment.