Skip to content

Commit 4d29167

Browse files
jaymellsvix-james
authored andcommitted
Fix Recover Failed Webhooks response
The current response doesn't match what our libraries expect, which results in exceptions when calling this endpoint with our libraries. This adds the minimal changes necessary to make the endpoint compliant.
1 parent da3f408 commit 4d29167

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

server/openapi.json

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@
149149
},
150150
"type": "object"
151151
},
152+
"BackgroundTaskStatus": {
153+
"enum": [
154+
"running"
155+
],
156+
"type": "string"
157+
},
158+
"BackgroundTaskType": {
159+
"enum": [
160+
"endpoint.recover"
161+
],
162+
"type": "string"
163+
},
152164
"DashboardAccessOut": {
153165
"properties": {
154166
"token": {
@@ -1980,6 +1992,25 @@
19801992
],
19811993
"type": "object"
19821994
},
1995+
"RecoverOut": {
1996+
"properties": {
1997+
"id": {
1998+
"type": "string"
1999+
},
2000+
"status": {
2001+
"$ref": "#/components/schemas/BackgroundTaskStatus"
2002+
},
2003+
"task": {
2004+
"$ref": "#/components/schemas/BackgroundTaskType"
2005+
}
2006+
},
2007+
"required": [
2008+
"id",
2009+
"status",
2010+
"task"
2011+
],
2012+
"type": "object"
2013+
},
19832014
"StatusCodeClass": {
19842015
"description": "The different classes of HTTP status codes:\n- CodeNone = 0\n- Code1xx = 100\n- Code2xx = 200\n- Code3xx = 300\n- Code4xx = 400\n- Code5xx = 500",
19852016
"enum": [
@@ -4402,7 +4433,14 @@
44024433
},
44034434
"responses": {
44044435
"202": {
4405-
"description": "no content"
4436+
"content": {
4437+
"application/json": {
4438+
"schema": {
4439+
"$ref": "#/components/schemas/RecoverOut"
4440+
}
4441+
}
4442+
},
4443+
"description": ""
44064444
},
44074445
"401": {
44084446
"content": {

server/svix-server/src/core/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ create_id_type!(
550550
);
551551
create_id_type!(MessageEndpointId, "msgep_");
552552
create_id_type!(EventTypeId, "evtype_");
553+
create_id_type!(QueueBackgroundTaskId, "qtask_");
553554

554555
create_all_id_types!(ApplicationId, ApplicationUid, ApplicationIdOrUid, "app_");
555556
create_all_id_types!(EndpointId, EndpointUid, EndpointIdOrUid, "ep_");

server/svix-server/src/v1/endpoints/endpoint/recovery.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
use axum::extract::{Path, State};
22
use chrono::{DateTime, Utc};
3+
use schemars::JsonSchema;
34
use sea_orm::{entity::prelude::*, QueryOrder, QuerySelect};
5+
use serde::{Deserialize, Serialize};
46
use svix_server_derive::aide_annotate;
57

68
use super::RecoverIn;
79
use crate::{
810
core::{
911
permissions,
10-
types::{BaseId, MessageAttemptTriggerType, MessageEndpointId, MessageStatus},
12+
types::{
13+
BaseId, MessageAttemptTriggerType, MessageEndpointId, MessageStatus,
14+
QueueBackgroundTaskId,
15+
},
1116
},
1217
db::models::{application, endpoint, messagedestination},
1318
error::{HttpError, Result, ValidationErrorItem},
1419
queue::{MessageTask, TaskQueueProducer},
15-
v1::utils::{ApplicationEndpointPath, NoContentWithCode, ValidatedJson},
20+
v1::utils::{ApplicationEndpointPath, JsonStatus, ValidatedJson},
1621
AppState,
1722
};
1823

@@ -66,6 +71,26 @@ async fn bulk_recover_failed_messages(
6671
Ok(())
6772
}
6873

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+
6994
/// Resend all failed messages since a given time.
7095
#[aide_annotate(op_id = "v1.endpoint.recover")]
7196
pub(super) async fn recover_failed_webhooks(
@@ -75,7 +100,7 @@ pub(super) async fn recover_failed_webhooks(
75100
Path(ApplicationEndpointPath { endpoint_id, .. }): Path<ApplicationEndpointPath>,
76101
permissions::Application { app }: permissions::Application,
77102
ValidatedJson(data): ValidatedJson<RecoverIn>,
78-
) -> Result<NoContentWithCode<202>> {
103+
) -> Result<JsonStatus<202, RecoverOut>> {
79104
// Add five minutes so that people can easily just do `now() - two_weeks` without having to worry about clock sync
80105
let timeframe = chrono::Duration::days(14);
81106
let timeframe = timeframe + chrono::Duration::minutes(5);
@@ -100,5 +125,9 @@ pub(super) async fn recover_failed_webhooks(
100125
async move { bulk_recover_failed_messages(db, queue_tx, app, endp, data.since).await },
101126
);
102127

103-
Ok(NoContentWithCode)
128+
Ok(JsonStatus(RecoverOut {
129+
id: QueueBackgroundTaskId::new(None, None),
130+
status: BackgroundTaskStatus::Running,
131+
task: BackgroundTaskType::Recover,
132+
}))
104133
}

0 commit comments

Comments
 (0)