feat(drainer): added drainer which reads from redis stream and executes queries on DB (#142)

This commit is contained in:
Abhishek
2022-12-16 15:38:03 +05:30
committed by GitHub
parent 3db49d0530
commit 3bad58b0d3
41 changed files with 648 additions and 655 deletions

View File

@ -0,0 +1,61 @@
use error_stack::{IntoReport, ResultExt};
use serde::{Deserialize, Serialize};
use crate::{
errors,
payment_attempt::{PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate},
payment_intent::{PaymentIntent, PaymentIntentNew, PaymentIntentUpdate},
};
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "db_op", content = "data")]
pub enum DBOperation {
Insert { insertable: Insertable },
Update { updatable: Updateable },
Delete,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TypedSql {
#[serde(flatten)]
pub op: DBOperation,
}
impl TypedSql {
pub fn to_field_value_pairs(
&self,
) -> crate::CustomResult<Vec<(&str, String)>, errors::DatabaseError> {
Ok(vec![(
"typed_sql",
serde_json::to_string(self)
.into_report()
.change_context(errors::DatabaseError::QueryGenerationFailed)?,
)])
}
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "table", content = "data")]
pub enum Insertable {
PaymentIntent(PaymentIntentNew),
PaymentAttempt(PaymentAttemptNew),
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "table", content = "data")]
pub enum Updateable {
PaymentIntentUpdate(PaymentIntentUpdateMems),
PaymentAttemptUpdate(PaymentAttemptUpdateMems),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PaymentIntentUpdateMems {
pub orig: PaymentIntent,
pub update_data: PaymentIntentUpdate,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PaymentAttemptUpdateMems {
pub orig: PaymentAttempt,
pub update_data: PaymentAttemptUpdate,
}