Skip to content

Commit 1c72974

Browse files
committed
wip
1 parent 67a7ab7 commit 1c72974

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

executors/src/eoa/events.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::fmt::Display;
22

3-
use engine_core::error::EngineError;
43
use serde::{Deserialize, Serialize};
54
use twmq::job::RequeuePosition;
65

76
use crate::{
87
eoa::{
98
store::{SubmittedTransaction, TransactionData},
10-
worker::ConfirmedTransactionWithRichReceipt,
9+
worker::{ConfirmedTransactionWithRichReceipt, EoaExecutorWorkerError},
1110
},
1211
webhook::envelope::{
13-
BareWebhookNotificationEnvelope, SerializableNackData, SerializableSuccessData, StageEvent,
12+
BareWebhookNotificationEnvelope, SerializableFailData, SerializableNackData,
13+
SerializableSuccessData, StageEvent,
1414
},
1515
};
1616

@@ -21,13 +21,12 @@ pub struct EoaExecutorEvent {
2121
#[derive(Debug, Clone, Serialize, Deserialize)]
2222
pub struct EoaSendAttemptNackData {
2323
pub nonce: u64,
24-
pub error: EngineError,
24+
pub error: EoaExecutorWorkerError,
2525
}
2626

2727
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2828
pub enum EoaExecutorStage {
2929
SendAttempt,
30-
SendAttemptNack,
3130
TransactionReplaced,
3231
TransactionConfirmed,
3332
}
@@ -36,7 +35,6 @@ impl Display for EoaExecutorStage {
3635
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3736
match self {
3837
EoaExecutorStage::SendAttempt => write!(f, "send_attempt"),
39-
EoaExecutorStage::SendAttemptNack => write!(f, "send_attempt_nack"),
4038
EoaExecutorStage::TransactionReplaced => write!(f, "transaction_replaced"),
4139
EoaExecutorStage::TransactionConfirmed => write!(f, "transaction_confirmed"),
4240
}
@@ -46,7 +44,7 @@ impl Display for EoaExecutorStage {
4644
const EXECUTOR_NAME: &str = "eoa";
4745

4846
impl EoaExecutorEvent {
49-
pub fn send_attempt_success_envelopes(
47+
pub fn send_attempt_success_envelope(
5048
&self,
5149
submitted_transaction: SubmittedTransaction,
5250
) -> BareWebhookNotificationEnvelope<SerializableSuccessData<SubmittedTransaction>> {
@@ -61,16 +59,16 @@ impl EoaExecutorEvent {
6159
}
6260
}
6361

64-
pub fn send_attempt_nack_envelopes(
62+
pub fn send_attempt_nack_envelope(
6563
&self,
6664
nonce: u64,
67-
error: EngineError,
65+
error: EoaExecutorWorkerError,
6866
attempt_number: u32,
6967
) -> BareWebhookNotificationEnvelope<SerializableNackData<EoaSendAttemptNackData>> {
7068
BareWebhookNotificationEnvelope {
7169
transaction_id: self.transaction_data.transaction_id.clone(),
7270
executor_name: EXECUTOR_NAME.to_string(),
73-
stage_name: EoaExecutorStage::SendAttemptNack.to_string(),
71+
stage_name: EoaExecutorStage::SendAttempt.to_string(),
7472
event_type: StageEvent::Nack,
7573
payload: SerializableNackData {
7674
error: EoaSendAttemptNackData {
@@ -86,7 +84,7 @@ impl EoaExecutorEvent {
8684
}
8785
}
8886

89-
pub fn transaction_replaced_envelopes(
87+
pub fn transaction_replaced_envelope(
9088
&self,
9189
replaced_transaction: SubmittedTransaction,
9290
) -> BareWebhookNotificationEnvelope<SerializableSuccessData<SubmittedTransaction>> {
@@ -101,7 +99,7 @@ impl EoaExecutorEvent {
10199
}
102100
}
103101

104-
pub fn transaction_confirmed_envelopes(
102+
pub fn transaction_confirmed_envelope(
105103
&self,
106104
confirmed_transaction: ConfirmedTransactionWithRichReceipt,
107105
) -> BareWebhookNotificationEnvelope<SerializableSuccessData<ConfirmedTransactionWithRichReceipt>>
@@ -116,4 +114,21 @@ impl EoaExecutorEvent {
116114
},
117115
}
118116
}
117+
118+
pub fn transaction_failed_envelope(
119+
&self,
120+
error: EoaExecutorWorkerError,
121+
final_attempt_number: u32,
122+
) -> BareWebhookNotificationEnvelope<SerializableFailData<EoaExecutorWorkerError>> {
123+
BareWebhookNotificationEnvelope {
124+
transaction_id: self.transaction_data.transaction_id.clone(),
125+
executor_name: EXECUTOR_NAME.to_string(),
126+
stage_name: EoaExecutorStage::SendAttempt.to_string(),
127+
event_type: StageEvent::Failure,
128+
payload: SerializableFailData {
129+
error: error.clone(),
130+
final_attempt_number,
131+
},
132+
}
133+
}
119134
}

executors/src/webhook/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::HashMap;
2-
use std::env;
32
use std::sync::Arc;
43
use std::time::{Duration, SystemTime, UNIX_EPOCH};
54

@@ -12,7 +11,6 @@ use twmq::error::TwmqError;
1211
use twmq::hooks::TransactionContext;
1312
use twmq::job::{BorrowedJob, JobError, JobResult, RequeuePosition, ToJobResult};
1413
use twmq::{DurableExecution, FailHookData, NackHookData, Queue, SuccessHookData, UserCancellable};
15-
use uuid::Uuid;
1614

1715
use crate::webhook::envelope::{BareWebhookNotificationEnvelope, WebhookNotificationEnvelope};
1816

@@ -479,7 +477,7 @@ pub fn queue_webhook_envelopes<T: Serialize + Clone>(
479477
hmac_secret: webhook_option.secret, // TODO: Add HMAC support if needed
480478
http_method: Some("POST".to_string()),
481479
};
482-
return (payload, webhook_notification_envelope);
480+
(payload, webhook_notification_envelope)
483481
},
484482
)
485483
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)