Update telemetry
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{
|
||||
authentication::AuthenticatedUser,
|
||||
idempotency::{IdempotencyKey, save_response, try_processing},
|
||||
@@ -15,6 +13,7 @@ use axum::{
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use sqlx::{Executor, Postgres, Transaction};
|
||||
use std::fmt::Display;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@@ -25,13 +24,14 @@ pub struct BodyData {
|
||||
idempotency_key: String,
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
#[tracing::instrument(name = "Creating newsletter isue", skip_all, fields(issue_id = tracing::field::Empty))]
|
||||
pub async fn insert_newsletter_issue(
|
||||
transaction: &mut Transaction<'static, Postgres>,
|
||||
title: &str,
|
||||
email_template: &dyn EmailTemplate,
|
||||
) -> Result<Uuid, sqlx::Error> {
|
||||
let newsletter_issue_id = Uuid::new_v4();
|
||||
tracing::Span::current().record("issue_id", newsletter_issue_id.to_string());
|
||||
let query = sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO newsletter_issues (
|
||||
@@ -48,6 +48,7 @@ pub async fn insert_newsletter_issue(
|
||||
Ok(newsletter_issue_id)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EmailType {
|
||||
NewPost,
|
||||
Newsletter,
|
||||
@@ -62,7 +63,7 @@ impl Display for EmailType {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
#[tracing::instrument(name = "Adding new task to queue", skip(transaction))]
|
||||
pub async fn enqueue_delivery_tasks(
|
||||
transaction: &mut Transaction<'static, Postgres>,
|
||||
newsletter_issue_id: Uuid,
|
||||
@@ -87,7 +88,7 @@ pub async fn enqueue_delivery_tasks(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(name = "Publishing a newsletter", skip(connection_pool, form))]
|
||||
#[tracing::instrument(name = "Publishing a newsletter", skip_all, fields(title = %form.title))]
|
||||
pub async fn publish_newsletter(
|
||||
State(AppState {
|
||||
connection_pool,
|
||||
@@ -134,12 +135,12 @@ pub async fn publish_newsletter(
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn validate_form(form: &BodyData) -> Result<(), &'static str> {
|
||||
fn validate_form(form: &BodyData) -> Result<(), anyhow::Error> {
|
||||
if form.title.is_empty() {
|
||||
return Err("The title was empty.");
|
||||
anyhow::bail!("The title was empty.");
|
||||
}
|
||||
if form.html.is_empty() || form.text.is_empty() {
|
||||
return Err("The content was empty.");
|
||||
anyhow::bail!("The content was empty.");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user