-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(notifications): complete the logic for sending email
- Loading branch information
1 parent
74b4986
commit 8466b93
Showing
10 changed files
with
159 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ app: | |
smtp: | ||
username: "" | ||
from_email: "" | ||
relay: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pub struct SmtpConfig { | |
#[serde(default)] | ||
pub password: String, | ||
pub from_email: String, | ||
pub relay: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
use thiserror::Error; | ||
|
||
use crate::push_executor::error::PushExecutorError; | ||
use crate::{email_executor::error::EmailExecutorError, push_executor::error::PushExecutorError}; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum JobError { | ||
#[error("JobError - Sqlx: {0}")] | ||
Sqlx(#[from] sqlx::Error), | ||
#[error("JobError - ExecutorError: {0}")] | ||
#[error("JobError - PushExecutorError: {0}")] | ||
PushExecutor(#[from] PushExecutorError), | ||
#[error("JobError - EmailExecutorError: {0}")] | ||
EmailExecutor(#[from] EmailExecutorError), | ||
} | ||
|
||
impl job_executor::JobExecutionError for JobError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tracing::instrument; | ||
|
||
use std::collections::HashMap; | ||
|
||
use super::error::JobError; | ||
use crate::{email_executor::EmailExecutor, notification_event::NotificationEventPayload}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub(super) struct SendEmailNotificationData { | ||
payload: NotificationEventPayload, | ||
#[serde(flatten)] | ||
pub(super) tracing_data: HashMap<String, serde_json::Value>, | ||
} | ||
|
||
impl From<NotificationEventPayload> for SendEmailNotificationData { | ||
fn from(payload: NotificationEventPayload) -> Self { | ||
Self { | ||
payload, | ||
tracing_data: tracing::extract_tracing_data(), | ||
} | ||
} | ||
} | ||
|
||
#[instrument(name = "job.send_email_notification", skip(executor), err)] | ||
pub async fn execute( | ||
data: SendEmailNotificationData, | ||
executor: EmailExecutor, | ||
) -> Result<SendEmailNotificationData, JobError> { | ||
executor.notify(&data.payload).await?; | ||
Ok(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters