Skip to content

Commit

Permalink
chore(notifications): rename executor to push_executor
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit committed Feb 15, 2024
1 parent 8531bfb commit 95d76c8
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions core/notifications/src/app/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};

use crate::executor::ExecutorConfig;
use crate::push_executor::PushExecutorConfig;

#[derive(Clone, Default, Serialize, Deserialize)]
pub struct AppConfig {
pub executor: ExecutorConfig,
pub executor: PushExecutorConfig,
}
4 changes: 2 additions & 2 deletions core/notifications/src/app/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use thiserror::Error;

use crate::{
executor::error::ExecutorError, job::error::JobError,
job::error::JobError, push_executor::error::PushExecutorError,
user_notification_settings::error::UserNotificationSettingsError,
};

Expand All @@ -12,7 +12,7 @@ pub enum ApplicationError {
#[error("{0}")]
JobError(#[from] JobError),
#[error("{0}")]
ExecutorError(#[from] ExecutorError),
PushExecutorError(#[from] PushExecutorError),
#[error("{0}")]
Sqlx(#[from] sqlx::Error),
}
4 changes: 2 additions & 2 deletions core/notifications/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing::instrument;
use std::sync::Arc;

use crate::{
executor::*, job, notification_event::*, primitives::*, user_notification_settings::*,
job, notification_event::*, primitives::*, push_executor::*, user_notification_settings::*,
};

pub use config::*;
Expand All @@ -25,7 +25,7 @@ pub struct NotificationsApp {
impl NotificationsApp {
pub async fn init(pool: Pool<Postgres>, config: AppConfig) -> Result<Self, ApplicationError> {
let settings = UserNotificationSettingsRepo::new(&pool);
let executor = Executor::init(config.executor.clone(), settings.clone()).await?;
let executor = PushExecutor::init(config.executor.clone(), settings.clone()).await?;
let runner = job::start_job_runner(&pool, executor).await?;
Ok(Self {
_config: config,
Expand Down
4 changes: 2 additions & 2 deletions core/notifications/src/job/error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use thiserror::Error;

use crate::executor::error::ExecutorError;
use crate::push_executor::error::PushExecutorError;

#[derive(Error, Debug)]
pub enum JobError {
#[error("JobError - Sqlx: {0}")]
Sqlx(#[from] sqlx::Error),
#[error("JobError - ExecutorError: {0}")]
Executor(#[from] ExecutorError),
PushExecutor(#[from] PushExecutorError),
}

impl job_executor::JobExecutionError for JobError {}
6 changes: 3 additions & 3 deletions core/notifications/src/job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use tracing::instrument;

use job_executor::JobExecutor;

use crate::executor::Executor;
use crate::push_executor::PushExecutor;

use error::JobError;

use send_push_notification::SendPushNotificationData;

pub async fn start_job_runner(
pool: &sqlx::PgPool,
executor: Executor,
executor: PushExecutor,
) -> Result<JobRunnerHandle, JobError> {
let mut registry = JobRegistry::new(&[send_push_notification]);
registry.set_context(executor);
Expand All @@ -29,7 +29,7 @@ pub async fn start_job_runner(
)]
async fn send_push_notification(
mut current_job: CurrentJob,
executor: Executor,
executor: PushExecutor,
) -> Result<(), JobError> {
JobExecutor::builder(&mut current_job)
.build()
Expand Down
4 changes: 2 additions & 2 deletions core/notifications/src/job/send_push_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing::instrument;
use std::collections::HashMap;

use super::error::JobError;
use crate::{executor::Executor, notification_event::NotificationEventPayload};
use crate::{notification_event::NotificationEventPayload, push_executor::PushExecutor};

#[derive(Debug, Serialize, Deserialize)]
pub(super) struct SendPushNotificationData {
Expand All @@ -25,7 +25,7 @@ impl From<NotificationEventPayload> for SendPushNotificationData {
#[instrument(name = "job.send_push_notification", skip(executor), err)]
pub async fn execute(
data: SendPushNotificationData,
executor: Executor,
executor: PushExecutor,
) -> Result<SendPushNotificationData, JobError> {
executor.notify(&data.payload).await?;
Ok(data)
Expand Down
2 changes: 1 addition & 1 deletion core/notifications/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mod job;
mod messages;

pub mod cli;
pub mod executor;
pub mod graphql;
pub mod grpc;
pub mod notification_event;
pub mod primitives;
pub mod push_executor;
pub mod user_notification_settings;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ use serde::{Deserialize, Serialize};
use super::fcm::FcmConfig;

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct ExecutorConfig {
pub struct PushExecutorConfig {
pub fcm: FcmConfig,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::fcm::error::FcmError;
use crate::user_notification_settings::error::*;

#[derive(Error, Debug)]
pub enum ExecutorError {
pub enum PushExecutorError {
#[error("ExecutorError - FcmError: {0}")]
Fcm(#[from] FcmError),
#[error("ExecutorError - UserNotificationSettingsError: {0}")]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ pub use config::*;
use error::*;

#[derive(Clone)]
pub struct Executor {
_config: ExecutorConfig,
pub struct PushExecutor {
_config: PushExecutorConfig,
fcm: FcmClient,
settings: UserNotificationSettingsRepo,
}

impl Executor {
impl PushExecutor {
pub async fn init(
mut config: ExecutorConfig,
mut config: PushExecutorConfig,
settings: UserNotificationSettingsRepo,
) -> Result<Self, ExecutorError> {
) -> Result<Self, PushExecutorError> {
Ok(Self {
fcm: FcmClient::init(config.fcm.service_account_key()).await?,
_config: config,
Expand All @@ -35,7 +35,7 @@ impl Executor {
fields(n_errors, n_removed_tokens),
err
)]
pub async fn notify<T: NotificationEvent>(&self, event: &T) -> Result<(), ExecutorError> {
pub async fn notify<T: NotificationEvent>(&self, event: &T) -> Result<(), PushExecutorError> {
let mut settings = self.settings.find_for_user_id(event.user_id()).await?;
if !settings.should_send_notification(UserNotificationChannel::Push, event.category()) {
return Ok(());
Expand Down

0 comments on commit 95d76c8

Please sign in to comment.