Skip to content

Commit 2284d70

Browse files
authored
feat: add qstash failureCallback to frontend (#4704)
1 parent 8d49c63 commit 2284d70

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/fern-docs/bundle/src/server/queue-reindex.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export const queueTurbopufferReindex = async (
2222
basepath,
2323
endpoint: "/api/fern-docs/search/v2/reindex/turbopuffer",
2424
method: "GET",
25-
timeoutSeconds
25+
timeoutSeconds,
26+
failureCallback: process.env.FAI_SERVER_URL
27+
? `${process.env.FAI_SERVER_URL}/upstash/qstash/failure-callback`
28+
: `https://fai.buildwithfern.com/upstash/qstash/failure-callback`
2629
});
2730
};
2831

@@ -54,7 +57,10 @@ export const queueTurbopufferStartReindex = async ({
5457
endpoint: endpoint as `/api/fern-docs/${string}`,
5558
method: "GET",
5659
timeoutSeconds,
57-
callback
60+
callback,
61+
failureCallback: process.env.FAI_SERVER_URL
62+
? `${process.env.FAI_SERVER_URL}/upstash/qstash/failure-callback`
63+
: `https://fai.buildwithfern.com/upstash/qstash/failure-callback`
5864
});
5965

6066
return messageId;

packages/fern-docs/bundle/src/server/queue.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export async function queue<TBody = unknown>({
2222
endpoint: endpointProp,
2323
disableVercelPreviewDeployment = false,
2424
timeoutSeconds,
25+
failureCallback,
2526
...request
2627
}: {
2728
/**
@@ -41,6 +42,10 @@ export async function queue<TBody = unknown>({
4142
retries?: number;
4243
deduplicationId?: string;
4344
disableVercelPreviewDeployment?: boolean;
45+
/**
46+
* URL to POST to when the job fails
47+
*/
48+
failureCallback?: string;
4449
}): Promise<void> {
4550
if (isLocal() || isSelfHosted() || q === undefined) {
4651
return undefined;
@@ -74,7 +79,8 @@ export async function queue<TBody = unknown>({
7479
...request,
7580
method: request.method === "HEAD" ? "GET" : request.method,
7681
headers,
77-
timeout: timeoutSeconds ? `${BigInt(timeoutSeconds)}s` : undefined
82+
timeout: timeoutSeconds ? `${BigInt(timeoutSeconds)}s` : undefined,
83+
failureCallback
7884
});
7985
}
8086

@@ -87,6 +93,7 @@ export async function queueWithMessageId<TBody = unknown>({
8793
method,
8894
timeoutSeconds,
8995
callback,
96+
failureCallback,
9097
...request
9198
}: {
9299
/**
@@ -113,6 +120,10 @@ export async function queueWithMessageId<TBody = unknown>({
113120
* URL to POST to when the job completes (success or failure)
114121
*/
115122
callback?: string;
123+
/**
124+
* URL to POST to when the job fails
125+
*/
126+
failureCallback?: string;
116127
}): Promise<string | undefined> {
117128
if (isLocal() || isSelfHosted() || q === undefined) {
118129
return undefined;
@@ -145,7 +156,8 @@ export async function queueWithMessageId<TBody = unknown>({
145156
headers,
146157
method,
147158
timeout: timeoutSeconds ? `${BigInt(timeoutSeconds)}s` : undefined,
148-
callback
159+
callback,
160+
failureCallback
149161
});
150162

151163
if ("messageId" in response) {

0 commit comments

Comments
 (0)