@dbos-inc/create 1.31.24-preview → 1.31.25-preview
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3 -4
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/dbos-drizzle/README.md +23 -0
- package/templates/dbos-drizzle/nodemon.json +7 -0
- package/templates/{hello-drizzle → dbos-drizzle}/package.json +1 -1
- package/templates/dbos-knex/README.md +23 -0
- package/templates/dbos-knex/nodemon.json +7 -0
- package/templates/{hello-contexts → dbos-knex}/package.json +3 -3
- package/templates/dbos-knex/src/main.ts +94 -0
- package/templates/dbos-prisma/README.md +23 -0
- package/templates/{hello-prisma → dbos-prisma}/nodemon.json +1 -1
- package/templates/{hello-prisma → dbos-prisma}/package.json +1 -1
- package/templates/{hello-express → dbos-prisma}/start_postgres_docker.js +0 -0
- package/templates/dbos-typeorm/README.md +23 -0
- package/templates/dbos-typeorm/nodemon.json +8 -0
- package/templates/{hello-typeorm → dbos-typeorm}/package.json +1 -1
- package/templates/{hello-nextjs → dbos-typeorm}/start_postgres_docker.js +0 -0
- package/templates/hello/.vscode/extensions.json +0 -7
- package/templates/hello/.vscode/launch.json +0 -21
- package/templates/hello/.vscode/tasks.json +0 -19
- package/templates/hello/README.md +0 -55
- package/templates/hello/dbos-config.yaml +0 -20
- package/templates/hello/eslint.config.js +0 -28
- package/templates/hello/gitignore.template +0 -144
- package/templates/hello/jest.config.js +0 -8
- package/templates/hello/knexfile.js +0 -20
- package/templates/hello/migrations/20240212161006_create_dbos_hello_tables.js +0 -18
- package/templates/hello/nodemon.json +0 -7
- package/templates/hello/package.json +0 -23
- package/templates/hello/src/operations.test.ts +0 -37
- package/templates/hello/src/operations.ts +0 -64
- package/templates/hello/start_postgres_docker.js +0 -40
- package/templates/hello/tsconfig.json +0 -25
- package/templates/hello-contexts/.vscode/extensions.json +0 -7
- package/templates/hello-contexts/.vscode/launch.json +0 -21
- package/templates/hello-contexts/.vscode/tasks.json +0 -19
- package/templates/hello-contexts/README.md +0 -76
- package/templates/hello-contexts/dbos-config.yaml +0 -20
- package/templates/hello-contexts/nodemon.json +0 -7
- package/templates/hello-contexts/src/operations.test.ts +0 -38
- package/templates/hello-contexts/src/operations.ts +0 -66
- package/templates/hello-drizzle/.vscode/extensions.json +0 -7
- package/templates/hello-drizzle/.vscode/launch.json +0 -21
- package/templates/hello-drizzle/.vscode/tasks.json +0 -19
- package/templates/hello-drizzle/README.md +0 -48
- package/templates/hello-drizzle/nodemon.json +0 -7
- package/templates/hello-express/README.md +0 -77
- package/templates/hello-express/knexfile.js +0 -20
- package/templates/hello-express/migrations/20240212161006_create_dbos_hello_tables.js +0 -18
- package/templates/hello-express/nodemon.json +0 -7
- package/templates/hello-express/package.json +0 -24
- package/templates/hello-express/src/main.ts +0 -99
- package/templates/hello-express/tsconfig.json +0 -25
- package/templates/hello-nextjs/README.md +0 -100
- package/templates/hello-nextjs/dbos-config.yaml +0 -18
- package/templates/hello-nextjs/eslint.config.mjs +0 -16
- package/templates/hello-nextjs/gitignore.template +0 -41
- package/templates/hello-nextjs/knexfile.js +0 -20
- package/templates/hello-nextjs/migrations/20240212161006_create_dbos_hello_tables.js +0 -18
- package/templates/hello-nextjs/next.config.ts +0 -18
- package/templates/hello-nextjs/package.json +0 -32
- package/templates/hello-nextjs/postcss.config.mjs +0 -8
- package/templates/hello-nextjs/public/file.svg +0 -1
- package/templates/hello-nextjs/public/globe.svg +0 -1
- package/templates/hello-nextjs/public/next.svg +0 -1
- package/templates/hello-nextjs/public/vercel.svg +0 -1
- package/templates/hello-nextjs/public/window.svg +0 -1
- package/templates/hello-nextjs/src/actions/dbosWorkflow.ts +0 -12
- package/templates/hello-nextjs/src/actions/hello.ts +0 -15
- package/templates/hello-nextjs/src/app/crash/route.ts +0 -8
- package/templates/hello-nextjs/src/app/favicon.ico +0 -0
- package/templates/hello-nextjs/src/app/globals.css +0 -21
- package/templates/hello-nextjs/src/app/greetings/route.ts +0 -11
- package/templates/hello-nextjs/src/app/layout.tsx +0 -34
- package/templates/hello-nextjs/src/app/page.tsx +0 -73
- package/templates/hello-nextjs/src/app/step/[slug]/route.ts +0 -15
- package/templates/hello-nextjs/src/app/tasks/[slug]/route.ts +0 -18
- package/templates/hello-nextjs/src/components/client/BackGroundTask.tsx +0 -179
- package/templates/hello-nextjs/src/components/client/callDBOSWorkflow.tsx +0 -31
- package/templates/hello-nextjs/src/dbos/background.ts +0 -23
- package/templates/hello-nextjs/src/dbos/hello.ts +0 -24
- package/templates/hello-nextjs/src/dbos/operations.ts +0 -9
- package/templates/hello-nextjs/tailwind.config.ts +0 -18
- package/templates/hello-nextjs/tsconfig.json +0 -29
- package/templates/hello-prisma/.vscode/extensions.json +0 -7
- package/templates/hello-prisma/.vscode/launch.json +0 -21
- package/templates/hello-prisma/.vscode/tasks.json +0 -19
- package/templates/hello-prisma/README.md +0 -51
- package/templates/hello-prisma/start_postgres_docker.js +0 -40
- package/templates/hello-typeorm/.vscode/extensions.json +0 -7
- package/templates/hello-typeorm/.vscode/launch.json +0 -21
- package/templates/hello-typeorm/.vscode/tasks.json +0 -19
- package/templates/hello-typeorm/README.md +0 -51
- package/templates/hello-typeorm/eslint.config.js +0 -28
- package/templates/hello-typeorm/gitignore.template +0 -144
- package/templates/hello-typeorm/jest.config.js +0 -8
- package/templates/hello-typeorm/nodemon.json +0 -8
- package/templates/hello-typeorm/start_postgres_docker.js +0 -40
- /package/templates/{hello-drizzle → dbos-drizzle}/dbos-config.yaml +0 -0
- /package/templates/{hello-drizzle → dbos-drizzle}/drizzle/0000_hello.sql +0 -0
- /package/templates/{hello-drizzle → dbos-drizzle}/drizzle/meta/0000_snapshot.json +0 -0
- /package/templates/{hello-drizzle → dbos-drizzle}/drizzle/meta/_journal.json +0 -0
- /package/templates/{hello-drizzle → dbos-drizzle}/drizzle.config.ts +0 -0
- /package/templates/{hello-contexts → dbos-drizzle}/eslint.config.js +0 -0
- /package/templates/{hello-contexts → dbos-drizzle}/gitignore.template +0 -0
- /package/templates/{hello-contexts → dbos-drizzle}/jest.config.js +0 -0
- /package/templates/{hello-drizzle → dbos-drizzle}/src/operations.test.ts +0 -0
- /package/templates/{hello-drizzle → dbos-drizzle}/src/operations.ts +0 -0
- /package/templates/{hello-drizzle → dbos-drizzle}/src/schema.ts +0 -0
- /package/templates/{hello-contexts → dbos-drizzle}/start_postgres_docker.js +0 -0
- /package/templates/{hello-contexts → dbos-drizzle}/tsconfig.json +0 -0
- /package/templates/{hello-express → dbos-knex}/dbos-config.yaml +0 -0
- /package/templates/{hello-drizzle → dbos-knex}/eslint.config.js +0 -0
- /package/templates/{hello-drizzle → dbos-knex}/gitignore.template +0 -0
- /package/templates/{hello-drizzle → dbos-knex}/jest.config.js +0 -0
- /package/templates/{hello-contexts → dbos-knex}/knexfile.js +0 -0
- /package/templates/{hello-contexts → dbos-knex}/migrations/20240212161006_create_dbos_hello_tables.js +0 -0
- /package/templates/{hello-express → dbos-knex}/src/main.test.ts +0 -0
- /package/templates/{hello-drizzle → dbos-knex}/start_postgres_docker.js +0 -0
- /package/templates/{hello-drizzle → dbos-knex}/tsconfig.json +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/dbos-config.yaml +0 -0
- /package/templates/{hello-express → dbos-prisma}/eslint.config.js +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/generate_env.js +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/gitignore.template +0 -0
- /package/templates/{hello-express → dbos-prisma}/jest.config.js +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/prisma/migrations/20240604184654_init/migration.sql +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/prisma/migrations/migration_lock.toml +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/prisma/schema.prisma +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/src/operations.test.ts +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/src/operations.ts +0 -0
- /package/templates/{hello-prisma → dbos-prisma}/tsconfig.json +0 -0
- /package/templates/{hello-typeorm → dbos-typeorm}/datasource.ts +0 -0
- /package/templates/{hello-typeorm → dbos-typeorm}/dbos-config.yaml +0 -0
- /package/templates/{hello-typeorm → dbos-typeorm}/entities/DBOSHello.ts +0 -0
- /package/templates/{hello-prisma → dbos-typeorm}/eslint.config.js +0 -0
- /package/templates/{hello-express → dbos-typeorm}/gitignore.template +0 -0
- /package/templates/{hello-prisma → dbos-typeorm}/jest.config.js +0 -0
- /package/templates/{hello-typeorm → dbos-typeorm}/migrations/1714934318136-DBOSHello.ts +0 -0
- /package/templates/{hello-typeorm → dbos-typeorm}/src/operations.test.ts +0 -0
- /package/templates/{hello-typeorm → dbos-typeorm}/src/operations.ts +0 -0
- /package/templates/{hello-typeorm → dbos-typeorm}/tsconfig.json +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Metadata } from "next";
|
|
2
|
-
import { Geist, Geist_Mono } from "next/font/google";
|
|
3
|
-
import "./globals.css";
|
|
4
|
-
|
|
5
|
-
const geistSans = Geist({
|
|
6
|
-
variable: "--font-geist-sans",
|
|
7
|
-
subsets: ["latin"],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const geistMono = Geist_Mono({
|
|
11
|
-
variable: "--font-geist-mono",
|
|
12
|
-
subsets: ["latin"],
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export const metadata: Metadata = {
|
|
16
|
-
title: "Create Next App with DBOS",
|
|
17
|
-
description: "Generated by DBOS",
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default function RootLayout({
|
|
21
|
-
children,
|
|
22
|
-
}: Readonly<{
|
|
23
|
-
children: React.ReactNode;
|
|
24
|
-
}>) {
|
|
25
|
-
return (
|
|
26
|
-
<html lang="en">
|
|
27
|
-
<body
|
|
28
|
-
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
|
29
|
-
>
|
|
30
|
-
{children}
|
|
31
|
-
</body>
|
|
32
|
-
</html>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import Image from "next/image";
|
|
2
|
-
import BackGroundTask from "@/components/client/BackGroundTask";
|
|
3
|
-
import CallDBOSWorkflow from "@/components/client/callDBOSWorkflow";
|
|
4
|
-
|
|
5
|
-
export default function Home() {
|
|
6
|
-
return (
|
|
7
|
-
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
|
8
|
-
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<h1 className="text-xl font-semibold mb-4">Welcome to DBOS!</h1>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<p className="mb-4">
|
|
15
|
-
DBOS helps you build applications that are <strong>resilient to any failure</strong>—no matter how many times you crash this app, your background task will always recover from its last completed step in about ten seconds.
|
|
16
|
-
</p>
|
|
17
|
-
<div>
|
|
18
|
-
<CallDBOSWorkflow wfResult="" />
|
|
19
|
-
</div>
|
|
20
|
-
<div>
|
|
21
|
-
<BackGroundTask />
|
|
22
|
-
</div>
|
|
23
|
-
</main>
|
|
24
|
-
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
|
|
25
|
-
<a
|
|
26
|
-
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
|
27
|
-
href="https://docs.dbos.dev/"
|
|
28
|
-
target="_blank"
|
|
29
|
-
rel="noopener noreferrer"
|
|
30
|
-
>
|
|
31
|
-
<Image
|
|
32
|
-
aria-hidden
|
|
33
|
-
src="/file.svg"
|
|
34
|
-
alt="File icon"
|
|
35
|
-
width={16}
|
|
36
|
-
height={16}
|
|
37
|
-
/>
|
|
38
|
-
Learn
|
|
39
|
-
</a>
|
|
40
|
-
<a
|
|
41
|
-
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
|
42
|
-
href="https://docs.dbos.dev/#example-applications"
|
|
43
|
-
target="_blank"
|
|
44
|
-
rel="noopener noreferrer"
|
|
45
|
-
>
|
|
46
|
-
<Image
|
|
47
|
-
aria-hidden
|
|
48
|
-
src="/window.svg"
|
|
49
|
-
alt="Window icon"
|
|
50
|
-
width={16}
|
|
51
|
-
height={16}
|
|
52
|
-
/>
|
|
53
|
-
Examples
|
|
54
|
-
</a>
|
|
55
|
-
<a
|
|
56
|
-
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
|
57
|
-
href="https://www.dbos.dev/"
|
|
58
|
-
target="_blank"
|
|
59
|
-
rel="noopener noreferrer"
|
|
60
|
-
>
|
|
61
|
-
<Image
|
|
62
|
-
aria-hidden
|
|
63
|
-
src="/globe.svg"
|
|
64
|
-
alt="Globe icon"
|
|
65
|
-
width={16}
|
|
66
|
-
height={16}
|
|
67
|
-
/>
|
|
68
|
-
Go to dbos.dev →
|
|
69
|
-
</a>
|
|
70
|
-
</footer>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
3
|
-
|
|
4
|
-
export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
|
|
5
|
-
|
|
6
|
-
const taskId = (await params).slug;
|
|
7
|
-
DBOS.logger.info(`Received request to check on taskId: ${taskId}`);
|
|
8
|
-
|
|
9
|
-
let step = await DBOS.getEvent(taskId, "steps_event");
|
|
10
|
-
|
|
11
|
-
DBOS.logger.info(`For taskId: ${taskId} we are done with ${step} steps`);
|
|
12
|
-
|
|
13
|
-
return NextResponse.json({ "stepsCompleted": step});
|
|
14
|
-
|
|
15
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
3
|
-
import { dbosBackgroundTask } from "@/actions/dbosWorkflow";
|
|
4
|
-
|
|
5
|
-
export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
|
|
6
|
-
|
|
7
|
-
const taskId = (await params).slug;
|
|
8
|
-
|
|
9
|
-
DBOS.logger.info(`Received request to start background task taskId: ${taskId}`);
|
|
10
|
-
|
|
11
|
-
DBOS.logger.info(`Started background task taskId: ${taskId}`);
|
|
12
|
-
|
|
13
|
-
await dbosBackgroundTask(taskId)
|
|
14
|
-
|
|
15
|
-
return NextResponse.json({ message: "Background task started" });
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useState, useEffect } from "react";
|
|
4
|
-
import { useRouter, useSearchParams } from "next/navigation";
|
|
5
|
-
import { Suspense } from 'react'
|
|
6
|
-
|
|
7
|
-
let intervalInitialized = false;
|
|
8
|
-
|
|
9
|
-
function generateRandomString(): string {
|
|
10
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
11
|
-
const array = new Uint8Array(6);
|
|
12
|
-
crypto.getRandomValues(array); // Fills the array with cryptographically random values
|
|
13
|
-
|
|
14
|
-
return Array.from(array)
|
|
15
|
-
.map(x => chars[x % chars.length])
|
|
16
|
-
.join('');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function BackGroundTask() {
|
|
20
|
-
const [isRunning, setIsRunning] = useState(false);
|
|
21
|
-
const [currentStep, setCurrentStep] = useState(0);
|
|
22
|
-
const [taskId, setTaskid] = useState("");
|
|
23
|
-
const [isReconnecting, setIsReconnecting] = useState(false);
|
|
24
|
-
|
|
25
|
-
const router = useRouter();
|
|
26
|
-
const searchParams = useSearchParams();
|
|
27
|
-
|
|
28
|
-
const startBackgroundJob = async () => {
|
|
29
|
-
setIsRunning(true);
|
|
30
|
-
|
|
31
|
-
setCurrentStep(0);
|
|
32
|
-
|
|
33
|
-
let task = taskId
|
|
34
|
-
if (taskId === "") {
|
|
35
|
-
task = generateRandomString();
|
|
36
|
-
setTaskid(task);
|
|
37
|
-
updateQueryParam("id", task);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// start the background job
|
|
41
|
-
try {
|
|
42
|
-
await fetch(`/tasks/${task}`, { method: "GET" });
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error("Failed to start job", error);
|
|
45
|
-
setIsRunning(false);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const crashApp = async () => {
|
|
50
|
-
|
|
51
|
-
if(!isRunning) {
|
|
52
|
-
console.log("Not running, nothing to crash");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setIsRunning(false);
|
|
57
|
-
|
|
58
|
-
console.log("Crashing the application");
|
|
59
|
-
|
|
60
|
-
// stop the background job
|
|
61
|
-
try {
|
|
62
|
-
await fetch("/crash", { method: "GET" });
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error("Failed to start job", error);
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Update the URL query parameter
|
|
71
|
-
const updateQueryParam = (key: string, value: string) => {
|
|
72
|
-
const params = new URLSearchParams(searchParams.toString());
|
|
73
|
-
params.set(key, value);
|
|
74
|
-
const newUrl = `${window.location.pathname}?${params.toString()}`;
|
|
75
|
-
router.replace(newUrl);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// Remove the `id` query parameter from the URL
|
|
79
|
-
const clearQueryParam = (key: string) => {
|
|
80
|
-
const params = new URLSearchParams(searchParams.toString());
|
|
81
|
-
params.delete(key);
|
|
82
|
-
const newUrl = `${window.location.pathname}?${params.toString()}`;
|
|
83
|
-
router.replace(newUrl);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// fetch the current progress
|
|
87
|
-
const fetchProgress = async () => {
|
|
88
|
-
try {
|
|
89
|
-
|
|
90
|
-
if (taskId === "") {
|
|
91
|
-
console.log("No task to monitor");
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const response = await fetch(`/step/${taskId}`, { method: "GET" });
|
|
96
|
-
if (!response.ok) {
|
|
97
|
-
console.error("Failed to fetch job progress", response.statusText);
|
|
98
|
-
setIsReconnecting(true);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
setIsReconnecting(false);
|
|
102
|
-
|
|
103
|
-
const data = await response.json();
|
|
104
|
-
|
|
105
|
-
console.log("Step completed", data.stepsCompleted);
|
|
106
|
-
|
|
107
|
-
if (data.stepsCompleted) {
|
|
108
|
-
setIsRunning(true);
|
|
109
|
-
setCurrentStep(data.stepsCompleted);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (data.stepsCompleted === 10) {
|
|
113
|
-
clearQueryParam("id");
|
|
114
|
-
setIsRunning(false);
|
|
115
|
-
setTaskid("");
|
|
116
|
-
setCurrentStep(0);
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error("Failed to fetch job progress", error);
|
|
122
|
-
setIsRunning(false);
|
|
123
|
-
setTaskid("");
|
|
124
|
-
setIsReconnecting(true);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// Polling the progress every 2 seconds while the job is running
|
|
129
|
-
useEffect(() => {
|
|
130
|
-
const idFromUrl = searchParams.get("id");
|
|
131
|
-
if (idFromUrl) {
|
|
132
|
-
setTaskid(idFromUrl);
|
|
133
|
-
setIsRunning(true); // Assume the job is already running if there's an ID
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!intervalInitialized) {
|
|
137
|
-
const interval = setInterval(fetchProgress, 2000);
|
|
138
|
-
intervalInitialized = true;
|
|
139
|
-
return () => {
|
|
140
|
-
clearInterval(interval);
|
|
141
|
-
intervalInitialized = false;
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}, [searchParams]);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
<div>
|
|
149
|
-
<div className="flex flex-row gap-2">
|
|
150
|
-
<button onClick={startBackgroundJob} disabled={isRunning} className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
|
|
151
|
-
{isRunning ? "Job in Progress..." : "Start Background Job"}
|
|
152
|
-
</button>
|
|
153
|
-
<button onClick={crashApp} disabled={!isRunning} className="px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600">
|
|
154
|
-
{ isRunning ? "Crash the application" : "Not Running"}
|
|
155
|
-
</button>
|
|
156
|
-
</div>
|
|
157
|
-
|
|
158
|
-
<p>
|
|
159
|
-
{currentStep < 10
|
|
160
|
-
? `Your background task has completed step ${currentStep} of 10.`
|
|
161
|
-
: "Background task completed successfully!"}
|
|
162
|
-
</p>
|
|
163
|
-
<p>
|
|
164
|
-
{isReconnecting ? "Reconnecting..." : ""}
|
|
165
|
-
</p>
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
</div>
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const WrappedBackgroundJobComponent = () => (
|
|
174
|
-
<Suspense fallback={<p>Loading...</p>}>
|
|
175
|
-
<BackGroundTask />
|
|
176
|
-
</Suspense>
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
export default WrappedBackgroundJobComponent;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
|
|
5
|
-
export default function CallDBOSWorkflow( { wfResult }: { wfResult: string }) {
|
|
6
|
-
const [greetingsWfResult, setGreetingsWfResult] = useState<string>(wfResult);
|
|
7
|
-
const [loading, setLoading] = useState<boolean>(false);
|
|
8
|
-
|
|
9
|
-
const greetUser = async () => {
|
|
10
|
-
setLoading(true);
|
|
11
|
-
try {
|
|
12
|
-
const response = await fetch("/greetings", { method: "POST", body: JSON.stringify({ userName: "dbosuser" }) });
|
|
13
|
-
const data = await response.json();
|
|
14
|
-
setGreetingsWfResult(data);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
console.error("Error calling greetings workflow", error);
|
|
17
|
-
setGreetingsWfResult("Error calling greetings workflow: " + error);
|
|
18
|
-
} finally {
|
|
19
|
-
setLoading(false);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return(
|
|
24
|
-
<div>
|
|
25
|
-
<button onClick={greetUser} disabled={loading} className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
|
|
26
|
-
{loading ? "" : "Run DBOS Workflow"}
|
|
27
|
-
</button>
|
|
28
|
-
<p>{greetingsWfResult}</p>
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
3
|
-
|
|
4
|
-
export class dbosWorkflowClass {
|
|
5
|
-
|
|
6
|
-
@DBOS.transaction()
|
|
7
|
-
static async backgroundTaskStep(i : number) {
|
|
8
|
-
DBOS.logger.info(`Completed step ${i}`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@DBOS.workflow()
|
|
12
|
-
static async backgroundTask(i: number) {
|
|
13
|
-
DBOS.logger.info("Hello from background task!");
|
|
14
|
-
for (let j = 1; j <= i; j++) {
|
|
15
|
-
await dbosWorkflowClass.backgroundTaskStep(j);
|
|
16
|
-
DBOS.logger.info("Sleeping for 2 seconds");
|
|
17
|
-
await DBOS.sleepSeconds(2);
|
|
18
|
-
await DBOS.setEvent("steps_event", j)
|
|
19
|
-
}
|
|
20
|
-
DBOS.logger.info("Background task complete!");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
2
|
-
import { Knex } from "knex";
|
|
3
|
-
|
|
4
|
-
export interface dbos_hello {
|
|
5
|
-
name: string;
|
|
6
|
-
greet_count: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function getClient() {return DBOS.knexClient as Knex;}
|
|
10
|
-
|
|
11
|
-
export class helloWorkflowClass {
|
|
12
|
-
|
|
13
|
-
@DBOS.transaction()
|
|
14
|
-
static async helloDBOS(userName: string) {
|
|
15
|
-
DBOS.logger.info("Hello from DBOS Transaction!");
|
|
16
|
-
// Retrieve and increment the number of times this user has been greeted.
|
|
17
|
-
const query = "INSERT INTO dbos_hello (name, greet_count) VALUES (?, 1) ON CONFLICT (name) DO UPDATE SET greet_count = dbos_hello.greet_count + 1 RETURNING greet_count;";
|
|
18
|
-
const { rows } = await getClient().raw(query, [userName]) as { rows: dbos_hello[] };
|
|
19
|
-
const greet_count = rows[0].greet_count;
|
|
20
|
-
const greeting = `Hello! You have been greeted ${greet_count} times.`;
|
|
21
|
-
return greeting;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
2
|
-
export { dbosWorkflowClass } from "./background";
|
|
3
|
-
export { helloWorkflowClass } from "./hello";
|
|
4
|
-
|
|
5
|
-
console.log("Hello from operations.ts");
|
|
6
|
-
|
|
7
|
-
if (process.env.NEXT_PHASE !== "phase-production-build") {
|
|
8
|
-
await DBOS.launch()
|
|
9
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Config } from "tailwindcss";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
content: [
|
|
5
|
-
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
|
|
6
|
-
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
|
7
|
-
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
|
8
|
-
],
|
|
9
|
-
theme: {
|
|
10
|
-
extend: {
|
|
11
|
-
colors: {
|
|
12
|
-
background: "var(--background)",
|
|
13
|
-
foreground: "var(--foreground)",
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
plugins: [],
|
|
18
|
-
} satisfies Config;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"experimentalDecorators": true,
|
|
4
|
-
"emitDecoratorMetadata": true,
|
|
5
|
-
"target": "ES2017",
|
|
6
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"noEmit": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"module": "esnext",
|
|
13
|
-
"moduleResolution": "bundler",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"isolatedModules": true,
|
|
16
|
-
"jsx": "preserve",
|
|
17
|
-
"incremental": true,
|
|
18
|
-
"plugins": [
|
|
19
|
-
{
|
|
20
|
-
"name": "next"
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
"paths": {
|
|
24
|
-
"@/*": ["./src/*"]
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
28
|
-
"exclude": ["node_modules"]
|
|
29
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Automatically configure the VSCode debugger for DBOS projects.
|
|
3
|
-
// Documentation on launch.json: https://go.microsoft.com/fwlink/?linkid=830387
|
|
4
|
-
"version": "0.2.0",
|
|
5
|
-
"configurations": [
|
|
6
|
-
{
|
|
7
|
-
"type": "node-terminal",
|
|
8
|
-
"request": "launch",
|
|
9
|
-
"name": "Local Debug",
|
|
10
|
-
"command": "npx dbos start",
|
|
11
|
-
"preLaunchTask": "npm: build",
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"type": "node-terminal",
|
|
15
|
-
"request": "launch",
|
|
16
|
-
"name": "Time Travel Debug",
|
|
17
|
-
"command": "npx dbos debug -x ${command:dbos-ttdbg.get-proxy-url} -u ${command:dbos-ttdbg.pick-workflow-id}",
|
|
18
|
-
"preLaunchTask": "npm: build"
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Configure the build command for DBOS projects using VSCode.
|
|
3
|
-
// Documentation on tasks.json: https://code.visualstudio.com/docs/editor/tasks
|
|
4
|
-
"version": "2.0.0",
|
|
5
|
-
"tasks": [
|
|
6
|
-
{
|
|
7
|
-
"label": "npm: build",
|
|
8
|
-
"type": "npm",
|
|
9
|
-
"script": "build",
|
|
10
|
-
"group": {
|
|
11
|
-
"kind": "build",
|
|
12
|
-
"isDefault": true
|
|
13
|
-
},
|
|
14
|
-
"problemMatcher": [
|
|
15
|
-
"$tsc"
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# DBOS Hello with Prisma
|
|
2
|
-
|
|
3
|
-
This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Prisma](https://docs.dbos.dev/typescript/tutorials/orms/using-prisma).
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
6
|
-
|
|
7
|
-
Before you can launch your app, you need a database.
|
|
8
|
-
DBOS works with any Postgres database, but to make things easier, we've provided a script that starts a Docker Postgres container and creates a database.
|
|
9
|
-
Run:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
node start_postgres_docker.js
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
If successful, the script should print `Database started successfully!`.
|
|
16
|
-
|
|
17
|
-
Next, build the app:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm run build
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Then, run a schema migration to create some tables.
|
|
24
|
-
Prisma provides rich support for [schema migrations](https://www.prisma.io/docs/orm/prisma-migrate), including automatic generation of migration files from Prisma schema.
|
|
25
|
-
Fore more information, see [our docs](https://docs.dbos.dev/typescript/tutorials/orms/using-prisma).
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npx dbos migrate
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
If successful, the migration should print `Migration successful!`.
|
|
32
|
-
|
|
33
|
-
Finally, run the app:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npx dbos start
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
To see that it's working, visit this URL in your browser: [`http://localhost:3000/greeting/dbos`](http://localhost:3000/greeting/dbos).
|
|
40
|
-
You should get this message: `Hello, dbos! You have been greeted 1 times.`
|
|
41
|
-
Each time you refresh the page, the counter should go up by one!
|
|
42
|
-
|
|
43
|
-
Congratulations! You just launched a DBOS application.
|
|
44
|
-
|
|
45
|
-
## Next Steps
|
|
46
|
-
|
|
47
|
-
- For more information on using Prisma with DBOS, check out [our docs](https://docs.dbos.dev/typescript/tutorials/orms/using-prisma).
|
|
48
|
-
- To add more functionality to this application, modify `src/operations.ts`, then rebuild and restart it. Alternatively, `npm run dev` uses `nodemon` to automatically rebuild and restart the app when source files change, using instructions specified in `nodemon.json`.
|
|
49
|
-
- For a detailed tutorial, check out our [programming quickstart](https://docs.dbos.dev/typescript/programming-guide).
|
|
50
|
-
- To learn how to deploy your application to DBOS Cloud, visit our [cloud quickstart](https://docs.dbos.dev/quickstart/)
|
|
51
|
-
- To learn more about DBOS, take a look at [our documentation](https://docs.dbos.dev/) or our [source code](https://github.com/dbos-inc).
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const { execSync } = require('child_process');
|
|
2
|
-
|
|
3
|
-
// Default PostgreSQL port
|
|
4
|
-
let port = '5432';
|
|
5
|
-
|
|
6
|
-
// Set the host PostgreSQL port with the -p/--port flag.
|
|
7
|
-
process.argv.forEach((val, index) => {
|
|
8
|
-
if (val === '-p' || val === '--port') {
|
|
9
|
-
if (process.argv[index + 1]) {
|
|
10
|
-
port = process.argv[index + 1];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
if (!process.env.PGPASSWORD) {
|
|
16
|
-
console.error("Error: PGPASSWORD is not set.");
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
execSync(`docker run --rm --name=dbos-db --env=POSTGRES_PASSWORD="${process.env.PGPASSWORD}" --env=PGDATA=/var/lib/postgresql/data --volume=/var/lib/postgresql/data -p ${port}:5432 -d sibedge/postgres-plv8`);
|
|
22
|
-
console.log("Waiting for PostgreSQL to start...");
|
|
23
|
-
|
|
24
|
-
let attempts = 30;
|
|
25
|
-
const checkDatabase = setInterval(() => {
|
|
26
|
-
try {
|
|
27
|
-
execSync('docker exec dbos-db psql -U postgres -c "SELECT 1;"', { stdio: 'ignore' });
|
|
28
|
-
console.log("PostgreSQL started!");
|
|
29
|
-
clearInterval(checkDatabase);
|
|
30
|
-
console.log("Database started successfully!");
|
|
31
|
-
} catch (error) {
|
|
32
|
-
if (--attempts === 0) {
|
|
33
|
-
clearInterval(checkDatabase);
|
|
34
|
-
console.error("Failed to start PostgreSQL.");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}, 1000);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error("Error starting PostgreSQL in Docker:", error.message);
|
|
40
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Automatically configure the VSCode debugger for DBOS projects.
|
|
3
|
-
// Documentation on launch.json: https://go.microsoft.com/fwlink/?linkid=830387
|
|
4
|
-
"version": "0.2.0",
|
|
5
|
-
"configurations": [
|
|
6
|
-
{
|
|
7
|
-
"type": "node-terminal",
|
|
8
|
-
"request": "launch",
|
|
9
|
-
"name": "Local Debug",
|
|
10
|
-
"command": "npx dbos start",
|
|
11
|
-
"preLaunchTask": "npm: build",
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"type": "node-terminal",
|
|
15
|
-
"request": "launch",
|
|
16
|
-
"name": "Time Travel Debug",
|
|
17
|
-
"command": "npx dbos debug -x ${command:dbos-ttdbg.get-proxy-url} -u ${command:dbos-ttdbg.pick-workflow-id}",
|
|
18
|
-
"preLaunchTask": "npm: build"
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Configure the build command for DBOS projects using VSCode.
|
|
3
|
-
// Documentation on tasks.json: https://code.visualstudio.com/docs/editor/tasks
|
|
4
|
-
"version": "2.0.0",
|
|
5
|
-
"tasks": [
|
|
6
|
-
{
|
|
7
|
-
"label": "npm: build",
|
|
8
|
-
"type": "npm",
|
|
9
|
-
"script": "build",
|
|
10
|
-
"group": {
|
|
11
|
-
"kind": "build",
|
|
12
|
-
"isDefault": true
|
|
13
|
-
},
|
|
14
|
-
"problemMatcher": [
|
|
15
|
-
"$tsc"
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|