Skip to content

Commit

Permalink
Add logging for email
Browse files Browse the repository at this point in the history
  • Loading branch information
malted committed Sep 19, 2024
1 parent e64cd65 commit 805eea6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "replit-takeout"
version = "1.7.15"
version = "1.7.16"
edition = "2021"
authors = ["Ben Dixon <malted@malted.dev>"]

Expand Down
6 changes: 6 additions & 0 deletions src/email/emails.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use log::info;
use once_cell::sync::Lazy;
use reqwest::{
header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE},
Expand Down Expand Up @@ -39,6 +40,7 @@ pub async fn send_greet_email(to: &str, username: &str) -> Result<()> {
});

send_loop(to, &payload).await?;
info!("Sent greet email to {to} ({username})");

Ok(())
}
Expand Down Expand Up @@ -69,6 +71,7 @@ pub async fn send_partial_success_email(
});

send_loop(to, &payload).await?;
info!("Sent partial success email to {to} ({username})");

Ok(())
}
Expand All @@ -90,6 +93,7 @@ pub async fn send_success_email(
});

send_loop(to, &payload).await?;
info!("Sent success email to {to} ({username})");

Ok(())
}
Expand All @@ -104,6 +108,7 @@ pub async fn send_failed_no_repls_email(to: &str, username: &str) -> Result<()>
});

send_loop(&to, &payload).await?;
info!("Sent failed no repls email to {to} ({username})");

Ok(())
}
Expand All @@ -118,6 +123,7 @@ pub async fn send_failure_email(to: &str, username: &str) -> Result<()> {
});

send_loop(&to, &payload).await?;
info!("Sent failure email to {to} ({username})");

Ok(())
}
26 changes: 19 additions & 7 deletions src/replit_graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,23 @@ impl ProfileRepls {
) -> Result<()> {
synced_user.fields.status = ProcessState::CollectingRepls;
synced_user.fields.started_at = Some(chrono::offset::Utc::now());
airtable::update_records(vec![synced_user.clone()]).await?;
airtable::update_records(vec![synced_user.clone()]).await?;

let client = create_client(token, None)?;

let current_user = QuickUser::fetch(token, Some(client.clone())).await?;
let current_user = match QuickUser::fetch(token, Some(client.clone())).await {
Ok(user) => user,
Err(err) => {
synced_user.fields.status = ProcessState::TokenExpired;
airtable::update_records(vec![synced_user.clone()]).await?;
error!(
"Issue with quickuser fetch - setting as expired token: {:?}",
err
);
return Ok(());
}
};

log::info!("current user: {:#?}", current_user);

fs::create_dir_all("repls").await?;
Expand All @@ -225,7 +237,7 @@ impl ProfileRepls {
}

synced_user.fields.status = ProcessState::NoRepls;
airtable::update_records(vec![synced_user.clone()]).await?;
airtable::update_records(vec![synced_user.clone()]).await?;
return Ok(());
}

Expand Down Expand Up @@ -342,13 +354,13 @@ impl ProfileRepls {
);

synced_user.fields.repl_count += 1;
airtable::update_records(vec![synced_user.clone()]).await?;
airtable::update_records(vec![synced_user.clone()]).await?;
progress.report(&current_user);
}

progress.completed = true;
progress.report(&current_user);
airtable::update_records(vec![synced_user.clone()]).await?;
airtable::update_records(vec![synced_user.clone()]).await?;

let path = format!("repls/{}", current_user.username);
make_zip(path.clone(), format!("repls/{}.zip", current_user.username)).await?;
Expand All @@ -365,11 +377,11 @@ impl ProfileRepls {
let upload_result = r2::upload(upload_path.clone(), zip_path.clone()).await;
fs::remove_file(&zip_path).await?;
synced_user.fields.status = ProcessState::WaitingInR2;
airtable::update_records(vec![synced_user.clone()]).await?;
airtable::update_records(vec![synced_user.clone()]).await?;

if let Err(upload_err) = upload_result {
synced_user.fields.status = ProcessState::ErroredR2;
airtable::update_records(vec![synced_user.clone()]).await?;
airtable::update_records(vec![synced_user.clone()]).await?;
error!("Failed to upload {upload_path} to R2");
return Err(upload_err);
}
Expand Down

0 comments on commit 805eea6

Please sign in to comment.