@@ -10,6 +10,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
10
10
use tokio:: runtime:: Runtime ;
11
11
use twmq:: error:: TwmqError ;
12
12
use twmq:: job:: JobError ;
13
+ use twmq:: { BorrowedJob , UserCancellable } ;
13
14
14
15
use twmq:: {
15
16
DurableExecution , Queue ,
@@ -44,6 +45,14 @@ impl From<TwmqError> for BenchmarkErrorData {
44
45
}
45
46
}
46
47
48
+ impl UserCancellable for BenchmarkErrorData {
49
+ fn user_cancelled ( ) -> Self {
50
+ BenchmarkErrorData {
51
+ reason : "Transaction cancelled by user" . to_string ( ) ,
52
+ }
53
+ }
54
+ }
55
+
47
56
// Shared metrics across all benchmark jobs
48
57
#[ derive( Clone ) ]
49
58
pub struct BenchmarkMetrics {
@@ -100,7 +109,10 @@ impl DurableExecution for BenchmarkJobHandler {
100
109
type ErrorData = BenchmarkErrorData ;
101
110
type JobData = BenchmarkJobData ;
102
111
103
- async fn process ( & self , job : & Job < Self :: JobData > ) -> JobResult < Self :: Output , Self :: ErrorData > {
112
+ async fn process (
113
+ & self ,
114
+ job : & BorrowedJob < Self :: JobData > ,
115
+ ) -> JobResult < Self :: Output , Self :: ErrorData > {
104
116
let start_time = SystemTime :: now ( )
105
117
. duration_since ( UNIX_EPOCH )
106
118
. unwrap ( )
@@ -119,7 +131,7 @@ impl DurableExecution for BenchmarkJobHandler {
119
131
. fetch_add ( processing_time, Ordering :: SeqCst ) ;
120
132
121
133
// Fresh random decision each processing attempt
122
- if rand:: thread_rng ( ) . gen_bool ( job. data . nack_probability ) {
134
+ if rand:: thread_rng ( ) . gen_bool ( job. job . data . nack_probability ) {
123
135
self . metrics . jobs_nacked . fetch_add ( 1 , Ordering :: SeqCst ) ;
124
136
125
137
// Random position for nacks as requested
@@ -140,7 +152,7 @@ impl DurableExecution for BenchmarkJobHandler {
140
152
self . metrics . jobs_succeeded . fetch_add ( 1 , Ordering :: SeqCst ) ;
141
153
142
154
Ok ( BenchmarkOutput {
143
- job_id : job. id . clone ( ) ,
155
+ job_id : job. id ( ) . to_string ( ) ,
144
156
processed_at : end_time,
145
157
} )
146
158
}
0 commit comments