Skip to content

Commit

Permalink
Merge pull request #69 from lucasishuman/failure-callback
Browse files Browse the repository at this point in the history
Add failure callback to message, publish request, schedules
  • Loading branch information
ogzhanolguncu authored Nov 6, 2023
2 parents 58955bf + 1c3536f commit d837cb0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DLQ } from "./dlq";
import { HttpClient, Requester, RetryConfig } from "./http";
import { Topics } from "./topics";
import { Messages } from "./messages";
import { Schedules } from "./schedules";
import { Topics } from "./topics";
import { Event } from "./types";
import { DLQ } from "./dlq";
type ClientConfig = {
/**
* Url of the qstash api server.
Expand Down Expand Up @@ -113,6 +113,15 @@ export type PublishRequest<TBody = BodyInit> = {
*/
callback?: string;

/**
* Use a failure callback url to handle messages that could not be delivered.
*
* The failure callback url must be publicly accessible
*
* @default undefined
*/
failureCallback?: string;

/**
* The method to use when sending a request to your API
*
Expand Down Expand Up @@ -230,6 +239,10 @@ export class Client {
headers.set("Upstash-Callback", req.callback);
}

if (typeof req.failureCallback !== "undefined") {
headers.set("Upstash-Failure-Callback", req.failureCallback);
}

const res = await this.http.request<PublishResponse<TRequest>>({
path: ["v2", "publish", req.url ?? req.topic],
body: req.body,
Expand Down
7 changes: 6 additions & 1 deletion src/client/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ export type Message = {
notBefore?: number;

/**
* A unix timestamp (milliseconds) when this messages was crated.
* A unix timestamp (milliseconds) when this messages was created.
*/
createdAt: number;

/**
* The callback url if configured.
*/
callback?: string;

/**
* The failure callback url if configured.
*/
failureCallback?: string;
};

export class Messages {
Expand Down
16 changes: 15 additions & 1 deletion src/client/schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Schedule = {
retries: number;
delay?: number;
callback?: string;
failureCallback?: string;
};

export type CreateScheduleRequest = {
Expand Down Expand Up @@ -47,7 +48,7 @@ export type CreateScheduleRequest = {
delay?: number;

/**
* In case your destination server is unavaialble or returns a status code outside of the 200-299
* In case your destination server is unavailable or returns a status code outside of the 200-299
* range, we will retry the request after a certain amount of time.
*
* Configure how many times you would like the delivery to be retried
Expand All @@ -65,6 +66,15 @@ export type CreateScheduleRequest = {
*/
callback?: string;

/**
* Use a failure callback url to handle messages that could not be delivered.
*
* The failure callback url must be publicly accessible
*
* @default undefined
*/
failureCallback?: string;

/**
* The method to use when sending a request to your API
*
Expand Down Expand Up @@ -113,6 +123,10 @@ export class Schedules {
headers.set("Upstash-Callback", req.callback);
}

if (typeof req.failureCallback !== "undefined") {
headers.set("Upstash-Failure-Callback", req.failureCallback);
}

return await this.http.request({
method: "POST",
headers,
Expand Down

0 comments on commit d837cb0

Please sign in to comment.