1
1
use axum:: extract:: { Path , State } ;
2
2
use chrono:: { DateTime , Utc } ;
3
+ use schemars:: JsonSchema ;
3
4
use sea_orm:: { entity:: prelude:: * , QueryOrder , QuerySelect } ;
5
+ use serde:: { Deserialize , Serialize } ;
4
6
use svix_server_derive:: aide_annotate;
5
7
6
8
use super :: RecoverIn ;
7
9
use crate :: {
8
10
core:: {
9
11
permissions,
10
- types:: { BaseId , MessageAttemptTriggerType , MessageEndpointId , MessageStatus } ,
12
+ types:: {
13
+ BaseId , MessageAttemptTriggerType , MessageEndpointId , MessageStatus ,
14
+ QueueBackgroundTaskId ,
15
+ } ,
11
16
} ,
12
17
db:: models:: { application, endpoint, messagedestination} ,
13
18
error:: { HttpError , Result , ValidationErrorItem } ,
14
19
queue:: { MessageTask , TaskQueueProducer } ,
15
- v1:: utils:: { ApplicationEndpointPath , NoContentWithCode , ValidatedJson } ,
20
+ v1:: utils:: { ApplicationEndpointPath , JsonStatus , ValidatedJson } ,
16
21
AppState ,
17
22
} ;
18
23
@@ -66,6 +71,26 @@ async fn bulk_recover_failed_messages(
66
71
Ok ( ( ) )
67
72
}
68
73
74
+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize , Deserialize , JsonSchema ) ]
75
+ #[ serde( rename_all = "camelCase" ) ]
76
+ pub enum BackgroundTaskStatus {
77
+ Running ,
78
+ }
79
+
80
+ #[ derive( Clone , Debug , Eq , PartialEq , Serialize , Deserialize , JsonSchema ) ]
81
+ pub enum BackgroundTaskType {
82
+ #[ serde( rename = "endpoint.recover" ) ]
83
+ Recover ,
84
+ }
85
+
86
+ #[ derive( Debug , Serialize , JsonSchema ) ]
87
+ #[ serde( rename_all = "camelCase" ) ]
88
+ pub struct RecoverOut {
89
+ id : QueueBackgroundTaskId ,
90
+ status : BackgroundTaskStatus ,
91
+ task : BackgroundTaskType ,
92
+ }
93
+
69
94
/// Resend all failed messages since a given time.
70
95
#[ aide_annotate( op_id = "v1.endpoint.recover" ) ]
71
96
pub ( super ) async fn recover_failed_webhooks (
@@ -75,7 +100,7 @@ pub(super) async fn recover_failed_webhooks(
75
100
Path ( ApplicationEndpointPath { endpoint_id, .. } ) : Path < ApplicationEndpointPath > ,
76
101
permissions:: Application { app } : permissions:: Application ,
77
102
ValidatedJson ( data) : ValidatedJson < RecoverIn > ,
78
- ) -> Result < NoContentWithCode < 202 > > {
103
+ ) -> Result < JsonStatus < 202 , RecoverOut > > {
79
104
// Add five minutes so that people can easily just do `now() - two_weeks` without having to worry about clock sync
80
105
let timeframe = chrono:: Duration :: days ( 14 ) ;
81
106
let timeframe = timeframe + chrono:: Duration :: minutes ( 5 ) ;
@@ -100,5 +125,9 @@ pub(super) async fn recover_failed_webhooks(
100
125
async move { bulk_recover_failed_messages ( db, queue_tx, app, endp, data. since ) . await } ,
101
126
) ;
102
127
103
- Ok ( NoContentWithCode )
128
+ Ok ( JsonStatus ( RecoverOut {
129
+ id : QueueBackgroundTaskId :: new ( None , None ) ,
130
+ status : BackgroundTaskStatus :: Running ,
131
+ task : BackgroundTaskType :: Recover ,
132
+ } ) )
104
133
}
0 commit comments