Skip to content

pratyushdeosingh/mdp / .agents/skills/dbos-golang

dbos-golang

Verified

DBOS Go SDK for building reliable, fault-tolerant applications with durable workflows. Use this skill when writing Go code with DBOS, creating workflows and steps, using queues, using the DBOS Clie...

references/comm-events.md

View on GitHub
---
title: Use Events for Workflow Status Publishing
impact: MEDIUM
impactDescription: Enables real-time progress monitoring and interactive workflows
tags: communication, events, status, key-value
---

## Use Events for Workflow Status Publishing

Workflows can publish events (key-value pairs) with `dbos.SetEvent`. Other code can read events with `dbos.GetEvent`. Events are persisted and useful for real-time progress monitoring.

**Incorrect (using external state for progress):**

```go
var progress int // Global variable - not durable!

func processData(ctx dbos.DBOSContext, input string) (string, error) {
	progress = 50 // Not persisted, lost on restart
	return input, nil
}
```

**Correct (using events):**

```go
func processData(ctx dbos.DBOSContext, input string) (string, error) {
	dbos.SetEvent(ctx, "status", "processing")
	_, err := dbos.RunAsStep(ctx, stepOne, dbos.WithStepName("stepOne"))
	if err != nil {
		return "", err
	}
	dbos.SetEvent(ctx, "progress", 50)
	_, err = dbos.RunAsStep(ctx, stepTwo, dbos.WithStepName("stepTwo"))
	if err != nil {
		return "", err
	}
	dbos.SetEvent(ctx, "progress", 100)
	dbos.SetEvent(ctx, "status", "complete")
	return "done", nil
}

// Read events from outside the workflow
status, err := dbos.GetEventstring
progress, err := dbos.GetEventint
```

Events are useful for interactive workflows. For example, a checkout workflow can publish a payment URL for the caller to redirect to:

```go
func checkoutWorkflow(ctx dbos.DBOSContext, order Order) (string, error) {
	paymentURL, err := dbos.RunAsStep(ctx, func(ctx context.Context) (string, error) {
		return createPayment(order)
	}, dbos.WithStepName("createPayment"))
	if err != nil {
		return "", err
	}
	dbos.SetEvent(ctx, "paymentURL", paymentURL)
	// Continue processing...
	return "success", nil
}

// HTTP handler starts workflow and reads the payment URL
handle, _ := dbos.RunWorkflow(ctx, checkoutWorkflow, order)
url, _ := dbos.GetEventstring, "paymentURL", 300*time.Second)
```

`GetEvent` blocks until the event is set or the timeout expires. It returns the zero value of the type if the timeout is reached.

Reference: [Workflow Events](https://docs.dbos.dev/golang/tutorials/workflow-communication#workflow-events)
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall