Skip to content

Commit

Permalink
fix: change qstash/Qstash as QStash
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Aug 21, 2024
1 parent deda8fb commit 0eeb1c0
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 140 deletions.
6 changes: 4 additions & 2 deletions examples/workflow/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Qstash Workflow Nextjs Example
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fupstash%2Fqstash-js%2Ftree%2Fmain%2Fexamples%2Fworkflow%2Fnextjs&env=QSTASH_TOKEN&project-name=qstash-workflow&repository-name=qstash-workflow&demo-title=Upstash%20-%20QStash%20Workflow%20Example&demo-description=A%20Next.js%20Application%20Utilizing%20QStash%20Workflows)

This project has some routes showcasing how Qstash Workflow can be used in a nextjs project.
# QStash Workflow Nextjs Example

This project has some routes showcasing how QStash Workflow can be used in a nextjs project.

Under the app directory, you will find 10 folders, each corresponding to a workflow API except the `-call-qstash`. The user calls `-call-qstash` with information about which endpoint is to be called in the body. `-call-qstash` publishes a message to QStash. QStash then calls the specified endpoint.

Expand Down
9 changes: 7 additions & 2 deletions examples/workflow/nextjs/app/path/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export const POST = serve<string>(
return output
});

const result2 = await context.run("step2", async () => {
const result2 = await Promise.all([ context.run("step2", async () => {
const output = someWork(result1)
console.log("step 2 input", result1, "output", output)
});
}), context.run("step2", async () => {
const output = someWork(result1)
console.log("step 2 input", result1, "output", output)
})]);

throw new Error("my -eror")
},
)
4 changes: 2 additions & 2 deletions examples/workflow/nuxt/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Qstash Workflow Nuxt Example
# QStash Workflow Nuxt Example

This project has some routes showcasing how Qstash Workflow can be used in a nuxt project.
This project has some routes showcasing how QStash Workflow can be used in a nuxt project.

Under the `server/api` directory, you will find 6 files, each corresponding to a workflow API except the `-call-qstash`.

Expand Down
4 changes: 2 additions & 2 deletions examples/workflow/solidjs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Qstash Workflow Solid.js Example
# QStash Workflow Solid.js Example

This project has some routes showcasing how Qstash Workflow can be used in a Solid.js project.
This project has some routes showcasing how QStash Workflow can be used in a Solid.js project.

Under the `src/routes` directory, you will find 7 files. `index.tsx` is the landing page. Rest except the `-call-qstash` are the routes corresponding to a workflow API.

Expand Down
4 changes: 2 additions & 2 deletions examples/workflow/sveltekit/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Qstash Workflow Sveltekit Example
# QStash Workflow Sveltekit Example

This project has some routes showcasing how Qstash Workflow can be used in a sveltekit project.
This project has some routes showcasing how QStash Workflow can be used in a sveltekit project.

Under the `src/routes` directory, you will find 6 folders, each corresponding to a workflow API except the `-call-qstash`.

Expand Down
2 changes: 1 addition & 1 deletion src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Workflow } from "./workflow";

type ClientConfig = {
/**
* Url of the qstash api server.
* Url of the QStash api server.
*
* This is only used for testing.
*
Expand Down
8 changes: 4 additions & 4 deletions src/client/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ export class QstashDailyRatelimitError extends QstashError {
/**
* Error raised during Workflow execution
*/
export class QstashWorkflowError extends QstashError {
export class QStashWorkflowError extends QstashError {
constructor(message: string) {
super(message);
this.name = "QstashWorkflowError";
this.name = "QStashWorkflowError";
}
}

/**
* Raised when the workflow executes a function and aborts
*/
export class QstashWorkflowAbort extends Error {
export class QStashWorkflowAbort extends Error {
public stepInfo?: Step;
public stepName: string;

Expand All @@ -81,7 +81,7 @@ export class QstashWorkflowAbort extends Error {
" Make sure that you await for each step. Also, if you are using try/catch blocks, you should not wrap context.run/sleep/sleepUntil/call methods with try/catch." +
` Aborting workflow after executing step '${stepName}'.`
);
this.name = "QstashWorkflowAbort";
this.name = "QStashWorkflowAbort";
this.stepName = stepName;
this.stepInfo = stepInfo;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/llm/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function checkStream(
expect(expectInStream.every((token) => text.includes(token))).toBeTrue();
}

describe("Test Qstash chat", () => {
describe("Test QStash chat", () => {
const client = new Client({ token: process.env.QSTASH_TOKEN! });

test(
Expand Down Expand Up @@ -173,7 +173,7 @@ describe("Test Qstash chat", () => {
});
});

describe("Test Qstash chat with third party LLMs", () => {
describe("Test QStash chat with third party LLMs", () => {
const client = new Client({ token: process.env.QSTASH_TOKEN! });

test(
Expand Down
44 changes: 22 additions & 22 deletions src/client/workflow/auto-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { describe, expect, spyOn, test } from "bun:test";
import { WorkflowContext } from "./context";
import { Client } from "../client";
import { MOCK_QSTASH_SERVER_URL, mockQstashServer, WORKFLOW_ENDPOINT } from "./test-utils";
import { MOCK_QSTASH_SERVER_URL, mockQStashServer, WORKFLOW_ENDPOINT } from "./test-utils";
import { nanoid } from "nanoid";
import { AutoExecutor } from "./auto-executor";
import type { Step } from "./types";
import { QstashWorkflowAbort, QstashWorkflowError } from "../error";
import { QStashWorkflowAbort, QStashWorkflowError } from "../error";

class SpyAutoExecutor extends AutoExecutor {
public declare getParallelCallState;
Expand Down Expand Up @@ -101,13 +101,13 @@ describe("auto-executor", () => {
const spyRunSingle = spyOn(context.executor, "runSingle");
const spyRunParallel = spyOn(context.executor, "runParallel");

await mockQstashServer({
await mockQStashServer({
// eslint-disable-next-line @typescript-eslint/require-await
execute: async () => {
const throws = context.run("attemptCharge", async () => {
return await Promise.resolve({ input: context.requestPayload, success: false });
});
expect(throws).rejects.toThrowError(QstashWorkflowAbort);
expect(throws).rejects.toThrowError(QStashWorkflowAbort);
},
responseFields: {
status: 200,
Expand Down Expand Up @@ -148,7 +148,7 @@ describe("auto-executor", () => {
const spyRunSingle = spyOn(context.executor, "runSingle");
const spyRunParallel = spyOn(context.executor, "runParallel");

await mockQstashServer({
await mockQStashServer({
execute: async () => {
expect(context.executor.stepCount).toBe(0);
expect(context.executor.planStepCount).toBe(0);
Expand Down Expand Up @@ -182,15 +182,15 @@ describe("auto-executor", () => {
const spyRunSingle = spyOn(context.executor, "runSingle");
const spyRunParallel = spyOn(context.executor, "runParallel");

await mockQstashServer({
await mockQStashServer({
// eslint-disable-next-line @typescript-eslint/require-await
execute: async () => {
expect(context.executor.getParallelCallState(2, 1)).toBe("first");
const throws = Promise.all([
context.sleep("sleep for some time", 123),
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(QstashWorkflowAbort);
expect(throws).rejects.toThrowError(QStashWorkflowAbort);
},
responseFields: {
status: 200,
Expand Down Expand Up @@ -248,15 +248,15 @@ describe("auto-executor", () => {
const spyRunSingle = spyOn(context.executor, "runSingle");
const spyRunParallel = spyOn(context.executor, "runParallel");

await mockQstashServer({
await mockQStashServer({
// eslint-disable-next-line @typescript-eslint/require-await
execute: async () => {
expect(context.executor.getParallelCallState(2, 1)).toBe("partial");
const throws = Promise.all([
context.sleep("sleep for some time", 123),
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(QstashWorkflowAbort);
expect(throws).rejects.toThrowError(QStashWorkflowAbort);
},
responseFields: {
status: 200,
Expand Down Expand Up @@ -300,15 +300,15 @@ describe("auto-executor", () => {
const spyRunSingle = spyOn(context.executor, "runSingle");
const spyRunParallel = spyOn(context.executor, "runParallel");

await mockQstashServer({
await mockQStashServer({
// eslint-disable-next-line @typescript-eslint/require-await
execute: async () => {
expect(context.executor.getParallelCallState(2, 1)).toBe("partial");
const throws = Promise.all([
context.sleep("sleep for some time", 123),
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(QstashWorkflowAbort);
expect(throws).rejects.toThrowError(QStashWorkflowAbort);
},
responseFields: {
status: 200,
Expand Down Expand Up @@ -352,15 +352,15 @@ describe("auto-executor", () => {
const spyRunSingle = spyOn(context.executor, "runSingle");
const spyRunParallel = spyOn(context.executor, "runParallel");

await mockQstashServer({
await mockQStashServer({
// eslint-disable-next-line @typescript-eslint/require-await
execute: async () => {
expect(context.executor.getParallelCallState(2, 1)).toBe("discard");
const throws = Promise.all([
context.sleep("sleep for some time", 123),
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(QstashWorkflowAbort);
expect(throws).rejects.toThrowError(QStashWorkflowAbort);
},
responseFields: {
status: 200,
Expand All @@ -386,7 +386,7 @@ describe("auto-executor", () => {
const spyRunSingle = spyOn(context.executor, "runSingle");
const spyRunParallel = spyOn(context.executor, "runParallel");

await mockQstashServer({
await mockQStashServer({
// eslint-disable-next-line @typescript-eslint/require-await
execute: async () => {
expect(context.executor.getParallelCallState(2, 1)).toBe("last");
Expand Down Expand Up @@ -429,7 +429,7 @@ describe("auto-executor", () => {
return await Promise.resolve(true);
});
expect(throws).rejects.toThrow(
new QstashWorkflowError(
new QStashWorkflowError(
"Incompatible step name. Expected 'wrongName', got 'attemptCharge' from the request"
)
);
Expand All @@ -438,7 +438,7 @@ describe("auto-executor", () => {
const context = getContext([initialStep, singleStep]);
const throws = context.sleep("attemptCharge", 10);
expect(throws).rejects.toThrow(
new QstashWorkflowError(
new QStashWorkflowError(
"Incompatible step type. Expected 'SleepFor', got 'Run' from the request"
)
);
Expand All @@ -455,7 +455,7 @@ describe("auto-executor", () => {
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrow(
new QstashWorkflowError(
new QStashWorkflowError(
"Incompatible step name. Expected 'wrongName', got 'sleep for some time' from the request"
)
);
Expand All @@ -469,7 +469,7 @@ describe("auto-executor", () => {
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrow(
new QstashWorkflowError(
new QStashWorkflowError(
"Incompatible step type. Expected 'SleepUntil', got 'SleepFor' from the request"
)
);
Expand All @@ -485,7 +485,7 @@ describe("auto-executor", () => {
context.sleep("wrongName", 10), // wrong step name
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(QstashWorkflowAbort);
expect(throws).rejects.toThrowError(QStashWorkflowAbort);
});
test("step type", () => {
const context = getContext([initialStep, ...parallelSteps.slice(0, 3)]);
Expand All @@ -495,7 +495,7 @@ describe("auto-executor", () => {
context.sleepUntil("sleep for some time", 10), // wrong step type
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(QstashWorkflowAbort);
expect(throws).rejects.toThrowError(QStashWorkflowAbort);
});
});

Expand All @@ -509,7 +509,7 @@ describe("auto-executor", () => {
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(
new QstashWorkflowError(
new QStashWorkflowError(
"Incompatible steps detected in parallel execution: Incompatible step name. Expected 'wrongName', got 'sleep for some time' from the request\n" +
' > Step Names from the request: ["sleep for some time","sleep until next day"]\n' +
' Step Types from the request: ["SleepFor","SleepUntil"]\n' +
Expand All @@ -527,7 +527,7 @@ describe("auto-executor", () => {
context.sleepUntil("sleep until next day", 123_123),
]);
expect(throws).rejects.toThrowError(
new QstashWorkflowError(
new QStashWorkflowError(
"Incompatible steps detected in parallel execution: Incompatible step type. Expected 'SleepUntil', got 'SleepFor' from the request\n" +
' > Step Names from the request: ["sleep for some time","sleep until next day"]\n' +
' Step Types from the request: ["SleepFor","SleepUntil"]\n' +
Expand Down
Loading

0 comments on commit 0eeb1c0

Please sign in to comment.