Skip to content

Commit 7950001

Browse files
committed
basic readme
1 parent 9570264 commit 7950001

File tree

1 file changed

+117
-1
lines changed

1 file changed

+117
-1
lines changed

README.md

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,120 @@
77

88
---
99

10-
# DBOS Transact Golang: In development
10+
## What is DBOS?
11+
12+
DBOS provides lightweight durable workflows on top of Postgres. Instead of managing your own workflow orchestrator or task queue system, you can use DBOS to add durable workflows and queues to your program in just a few lines of code.
13+
14+
## Getting started
15+
16+
Install the DBOS Transact package in your program:
17+
18+
```shell
19+
github.com/dbos-inc/dbos-transact-go
20+
```
21+
22+
## Features
23+
<details open><summary><strong>💾 Durable Workflows</strong></summary>
24+
25+
DBOS workflows make your program **durable** by checkpointing its state in Postgres.
26+
If your program ever fails, when it restarts all your workflows will automatically resume from the last completed step.
27+
28+
You add durable workflows to your existing Golang program by registering ordinary functions as workflows or running them as steps:
29+
30+
```golang
31+
var (
32+
wf = dbos.WithWorkflow(workflow)
33+
)
34+
35+
func workflow(ctx context.Context, _ string) (string, error) {
36+
_, err := dbos.RunAsStep(ctx, step1, "")
37+
if err != nil {
38+
return "", err
39+
}
40+
return dbos.RunAsStep(ctx, step2, "")
41+
}
42+
43+
func step1(ctx context.Context, _ string) (string, error) {
44+
fmt.Println("Executing step 1")
45+
return "Step 1 completed", nil
46+
}
47+
48+
func step2(ctx context.Context, _ string) (string, error) {
49+
fmt.Println("Executing step 2")
50+
return "Step 2 completed - Workflow finished successfully", nil
51+
}
52+
53+
func main() {
54+
err := dbos.Launch()
55+
if err != nil {
56+
panic(err)
57+
}
58+
defer dbos.Shutdown()
59+
60+
wf(context.Background(), "hello DBOS")
61+
}
62+
```
63+
64+
65+
Workflows are particularly useful for
66+
67+
- Orchestrating business processes so they seamlessly recover from any failure.
68+
- Building observable and fault-tolerant data pipelines.
69+
- Operating an AI agent, or any application that relies on unreliable or non-deterministic APIs.
70+
71+
</details>
72+
73+
<details><summary><strong>📒 Durable Queues</strong></summary>
74+
75+
####
76+
77+
DBOS queues help you **durably** run tasks in the background.
78+
When you enqueue a workflow, one of your processes will pick it up for execution.
79+
DBOS manages the execution of your tasks: it guarantees that tasks complete, and that their callers get their results without needing to resubmit them, even if your application is interrupted.
80+
81+
Queues also provide flow control, so you can limit the concurrency of your tasks on a per-queue or per-process basis.
82+
You can also set timeouts for tasks, rate limit how often queued tasks are executed, deduplicate tasks, or prioritize tasks.
83+
84+
You can add queues to your workflows in just a couple lines of code.
85+
They don't require a separate queueing service or message broker&mdash;just Postgres.
86+
87+
```golang
88+
var (
89+
queue = dbos.NewWorkflowQueue("example-queue")
90+
taskWf = dbos.WithWorkflow(task)
91+
)
92+
93+
func task(ctx context.Context, i int) (int, error) {
94+
time.Sleep(5 * time.Second)
95+
fmt.Printf("Task %d completed\n", i)
96+
return i, nil
97+
}
98+
99+
func main() {
100+
err := dbos.Launch()
101+
if err != nil {
102+
panic(err)
103+
}
104+
defer dbos.Shutdown()
105+
106+
fmt.Println("Enqueuing workflows")
107+
handles := make([]dbos.WorkflowHandle[int], 10)
108+
for i := range 10 {
109+
handle, err := taskWf(ctx, i, dbos.WithQueue(queue.Name))
110+
if err != nil {
111+
return "", fmt.Errorf("failed to enqueue step %d: %w", i, err)
112+
}
113+
handles[i] = handle
114+
}
115+
results := make([]int, 10)
116+
for i, handle := range handles {
117+
result, err := handle.GetResult(ctx)
118+
if err != nil {
119+
return "", fmt.Errorf("failed to get result for step %d: %w", i, err)
120+
}
121+
results[i] = result
122+
}
123+
fmt.Printf("Successfully completed %d steps\n", len(results)), nil
124+
}
125+
```
126+
</details>

0 commit comments

Comments
 (0)