Moved logging for task worker inside task execution logic
This commit is contained in:
File diff suppressed because one or more lines are too long
3
package-lock.json
generated
3
package-lock.json
generated
@@ -1123,7 +1123,8 @@
|
|||||||
"version": "4.1.13",
|
"version": "4.1.13",
|
||||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.13.tgz",
|
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.13.tgz",
|
||||||
"integrity": "sha512-i+zidfmTqtwquj4hMEwdjshYYgMbOrPzb9a0M3ZgNa0JMoZeFC6bxZvO8yr8ozS6ix2SDz0+mvryPeBs2TFE+w==",
|
"integrity": "sha512-i+zidfmTqtwquj4hMEwdjshYYgMbOrPzb9a0M3ZgNa0JMoZeFC6bxZvO8yr8ozS6ix2SDz0+mvryPeBs2TFE+w==",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/tapable": {
|
"node_modules/tapable": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Debug, Validate)]
|
#[derive(Debug, Validate)]
|
||||||
@@ -22,6 +24,12 @@ impl AsRef<str> for SubscriberEmail {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for SubscriberEmail {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.email)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::SubscriberEmail;
|
use super::SubscriberEmail;
|
||||||
|
|||||||
@@ -31,14 +31,6 @@ pub enum ExecutionOutcome {
|
|||||||
EmptyQueue,
|
EmptyQueue,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(
|
|
||||||
skip_all,
|
|
||||||
fields(
|
|
||||||
newsletter_issue_id=tracing::field::Empty,
|
|
||||||
subscriber_email=tracing::field::Empty
|
|
||||||
),
|
|
||||||
err
|
|
||||||
)]
|
|
||||||
pub async fn try_execute_task(
|
pub async fn try_execute_task(
|
||||||
connection_pool: &PgPool,
|
connection_pool: &PgPool,
|
||||||
email_client: &EmailClient,
|
email_client: &EmailClient,
|
||||||
@@ -53,25 +45,14 @@ pub async fn try_execute_task(
|
|||||||
.record("subscriber_email", display(&task.subscriber_email));
|
.record("subscriber_email", display(&task.subscriber_email));
|
||||||
match SubscriberEmail::parse(task.subscriber_email.clone()) {
|
match SubscriberEmail::parse(task.subscriber_email.clone()) {
|
||||||
Ok(email) => {
|
Ok(email) => {
|
||||||
let mut issue = get_issue(connection_pool, task.newsletter_issue_id).await?;
|
execute_task(
|
||||||
issue.inject_unsubscribe_token(&task.unsubscribe_token);
|
connection_pool,
|
||||||
if task.kind == EmailType::NewPost.to_string() {
|
&mut transaction,
|
||||||
issue.inject_tracking_info(&mut transaction).await?;
|
&task,
|
||||||
}
|
email,
|
||||||
if let Err(e) = email_client
|
email_client,
|
||||||
.send_email(
|
)
|
||||||
&email,
|
.await?;
|
||||||
&issue.title,
|
|
||||||
&issue.html_content,
|
|
||||||
&issue.text_content,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
tracing::error!(
|
|
||||||
error = %e,
|
|
||||||
"Failed to deliver issue to confirmed subscriber. Skipping."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
@@ -178,6 +159,35 @@ async fn dequeue_task(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(
|
||||||
|
name = "Executing task",
|
||||||
|
skip_all,
|
||||||
|
fields(email = %email),
|
||||||
|
)]
|
||||||
|
async fn execute_task(
|
||||||
|
connection_pool: &PgPool,
|
||||||
|
transaction: &mut Transaction<'static, Postgres>,
|
||||||
|
task: &Task,
|
||||||
|
email: SubscriberEmail,
|
||||||
|
email_client: &EmailClient,
|
||||||
|
) -> Result<(), anyhow::Error> {
|
||||||
|
let mut issue = get_issue(connection_pool, task.newsletter_issue_id).await?;
|
||||||
|
issue.inject_unsubscribe_token(&task.unsubscribe_token);
|
||||||
|
if task.kind == EmailType::NewPost.to_string() {
|
||||||
|
issue.inject_tracking_info(transaction).await?;
|
||||||
|
}
|
||||||
|
email_client
|
||||||
|
.send_email(
|
||||||
|
&email,
|
||||||
|
&issue.title,
|
||||||
|
&issue.html_content,
|
||||||
|
&issue.text_content,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.context("Failed to deliver newsletter issue to subscriber..")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn delete_task(
|
async fn delete_task(
|
||||||
mut transaction: Transaction<'static, Postgres>,
|
mut transaction: Transaction<'static, Postgres>,
|
||||||
issue_id: Uuid,
|
issue_id: Uuid,
|
||||||
|
|||||||
Reference in New Issue
Block a user