Skip to content

Commit 8ba9665

Browse files
authored
Contributing (#67)
- Add `CONTRIBUTING.md` - Add licence badge in `README.md` - Privatize a few types - Fix package level `RetrieveWorkflow` (now calls interface `RetrieveWorkflow`) - Few type casting checks & a fix (in `RunAsWorkflow` we shouldn't cast to the concrete type) - Clean up all options names and visibility (option structs are public, fields are private. Harmonize names across the board)
1 parent abb9d03 commit 8ba9665

File tree

9 files changed

+301
-296
lines changed

9 files changed

+301
-296
lines changed

CONTRIBUTING.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Contributing to DBOS Transact Python
2+
3+
Thank you for considering contributing to DBOS Transact. We welcome contributions from everyone, including bug fixes, feature enhancements, documentation improvements, or any other form of contribution.
4+
5+
## How to Contribute
6+
7+
To get started with DBOS Transact, please read the [README](README.md).
8+
9+
You can contribute in many ways. Some simple ways are:
10+
* Use the SDK and open issues to report any bugs, questions, concern with the SDK, samples or documentation.
11+
* Respond to issues with advice or suggestions.
12+
* Participate in discussions in our [Discord](https://discord.gg/fMwQjeW5zg) channel.
13+
* Contribute fixes and improvement to code, samples or documentation.
14+
15+
### To contribute code, please follow these steps:
16+
17+
1. Fork this github repository to your own account.
18+
19+
2. Clone the forked repository to your local machine.
20+
21+
3. Create a branch.
22+
23+
4. Make the necessary change to code, samples or documentation.
24+
25+
5. Write tests.
26+
27+
6. Commit the changes to your forked repository.
28+
29+
7. Submit a pull request to this repository.
30+
In the PR description please include:
31+
* Description of the fix/feature.
32+
* Brief description of implementation.
33+
* Description of how you tested the fix.
34+
35+
## Requesting features
36+
37+
If you have a feature request or an idea for an enhancement, feel free to open an issue on GitHub. Describe the feature or enhancement you'd like to see and why it would be valuable. Discuss it with the community on the [Discord](https://discord.gg/fMwQjeW5zg) channel.
38+
39+
## Discuss with the community
40+
41+
If you are stuck, need help, or wondering if a certain contribution will be welcome, please ask! You can reach out to us on [Discord](https://discord.gg/fMwQjeW5zg) or Github discussions.
42+
43+
## Code of conduct
44+
45+
It is important to us that contributing to DBOS will be a pleasant experience, if necessary, please refer to our [code of conduct](CODE_OF_CONDUCT.md) for participation guidelines.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Go Report Card](https://goreportcard.com/badge/github.com/dbos-inc/dbos-transact-go)](https://goreportcard.com/report/github.com/dbos-inc/dbos-transact-go)
55
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/dbos-inc/dbos-transact-go?sort=semver)](https://github.com/dbos-inc/dbos-transact-go/releases)
66
[![Join Discord](https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white)](https://discord.com/invite/jsmC6pXGgX)
7+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
78

89

910
# DBOS Transact: Lightweight Durable Workflow Orchestration with Postgres

dbos/admin_server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func newAdminServer(ctx *dbosContext, port int) *adminServer {
287287
}
288288
}
289289

290-
workflows, err := ctx.ListWorkflows(req.toListWorkflowsOptions()...)
290+
workflows, err := ListWorkflows(ctx, req.toListWorkflowsOptions()...)
291291
if err != nil {
292292
ctx.logger.Error("Failed to list workflows", "error", err)
293293
http.Error(w, fmt.Sprintf("Failed to list workflows: %v", err), http.StatusInternalServerError)
@@ -313,7 +313,7 @@ func newAdminServer(ctx *dbosContext, port int) *adminServer {
313313

314314
// Use ListWorkflows with the specific workflow ID filter
315315
opts := []ListWorkflowsOption{WithWorkflowIDs([]string{workflowID})}
316-
workflows, err := ctx.ListWorkflows(opts...)
316+
workflows, err := ListWorkflows(ctx, opts...)
317317
if err != nil {
318318
ctx.logger.Error("Failed to get workflow", "workflow_id", workflowID, "error", err)
319319
http.Error(w, fmt.Sprintf("Failed to get workflow: %v", err), http.StatusInternalServerError)
@@ -346,7 +346,7 @@ func newAdminServer(ctx *dbosContext, port int) *adminServer {
346346
}
347347
}
348348

349-
workflows, err := ctx.ListWorkflows(req.toListWorkflowsOptions()...)
349+
workflows, err := ListWorkflows(ctx, req.toListWorkflowsOptions()...)
350350
if err != nil {
351351
ctx.logger.Error("Failed to list queued workflows", "error", err)
352352
http.Error(w, fmt.Sprintf("Failed to list queued workflows: %v", err), http.StatusInternalServerError)

dbos/admin_server_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func TestAdminServer(t *testing.T) {
4444
// Verify the DBOS executor doesn't have an admin server instance
4545
require.NotNil(t, ctx, "Expected DBOS instance to be created")
4646

47-
exec := ctx.(*dbosContext)
47+
exec, ok := ctx.(*dbosContext)
48+
require.True(t, ok, "Expected ctx to be of type *dbosContext")
4849
require.Nil(t, exec.adminServer, "Expected admin server to be nil when not configured")
4950
})
5051

dbos/client_test.go

Lines changed: 47 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ func TestEnqueue(t *testing.T) {
6868

6969
t.Run("EnqueueAndGetResult", func(t *testing.T) {
7070
// Client enqueues a task using the new Enqueue method
71-
handle, err := Enqueue[wfInput, string](clientCtx, GenericEnqueueOptions[wfInput]{
72-
WorkflowName: "ServerWorkflow",
73-
QueueName: queue.Name,
74-
WorkflowInput: wfInput{Input: "test-input"},
75-
ApplicationVersion: serverCtx.GetApplicationVersion(),
76-
})
71+
handle, err := Enqueue[wfInput, string](clientCtx, queue.Name, "ServerWorkflow", wfInput{Input: "test-input"},
72+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
7773
require.NoError(t, err)
7874

7975
// Verify we got a polling handle
@@ -102,12 +98,8 @@ func TestEnqueue(t *testing.T) {
10298
customWorkflowID := "custom-client-workflow-id"
10399

104100
// Client enqueues a task with a custom workflow ID
105-
_, err := Enqueue[wfInput, string](clientCtx, GenericEnqueueOptions[wfInput]{
106-
WorkflowName: "ServerWorkflow",
107-
QueueName: queue.Name,
108-
WorkflowID: customWorkflowID,
109-
WorkflowInput: wfInput{Input: "test-input"},
110-
})
101+
_, err := Enqueue[wfInput, string](clientCtx, queue.Name, "ServerWorkflow", wfInput{Input: "test-input"},
102+
WithEnqueueWorkflowID(customWorkflowID))
111103
require.NoError(t, err)
112104

113105
// Verify the workflow ID is what we set
@@ -123,12 +115,8 @@ func TestEnqueue(t *testing.T) {
123115
})
124116

125117
t.Run("EnqueueWithTimeout", func(t *testing.T) {
126-
handle, err := Enqueue[string, string](clientCtx, GenericEnqueueOptions[string]{
127-
WorkflowName: "BlockingWorkflow",
128-
QueueName: queue.Name,
129-
WorkflowInput: "blocking-input",
130-
WorkflowTimeout: 500 * time.Millisecond,
131-
})
118+
handle, err := Enqueue[string, string](clientCtx, queue.Name, "BlockingWorkflow", "blocking-input",
119+
WithEnqueueTimeout(500*time.Millisecond))
132120
require.NoError(t, err)
133121

134122
// Should timeout when trying to get result
@@ -154,32 +142,20 @@ func TestEnqueue(t *testing.T) {
154142
mu.Unlock()
155143

156144
// Enqueue workflow without priority (will use default priority of 0)
157-
handle1, err := Enqueue[string, string](clientCtx, GenericEnqueueOptions[string]{
158-
WorkflowName: "PriorityWorkflow",
159-
QueueName: priorityQueue.Name,
160-
WorkflowInput: "abc",
161-
ApplicationVersion: serverCtx.GetApplicationVersion(),
162-
})
145+
handle1, err := Enqueue[string, string](clientCtx, priorityQueue.Name, "PriorityWorkflow", "abc",
146+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
163147
require.NoError(t, err, "failed to enqueue workflow without priority")
164148

165149
// Enqueue with a lower priority (higher number = lower priority)
166-
handle2, err := Enqueue[string, string](clientCtx, GenericEnqueueOptions[string]{
167-
WorkflowName: "PriorityWorkflow",
168-
QueueName: priorityQueue.Name,
169-
WorkflowInput: "def",
170-
Priority: 5,
171-
ApplicationVersion: serverCtx.GetApplicationVersion(),
172-
})
150+
handle2, err := Enqueue[string, string](clientCtx, priorityQueue.Name, "PriorityWorkflow", "def",
151+
WithEnqueuePriority(5),
152+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
173153
require.NoError(t, err, "failed to enqueue workflow with priority 5")
174154

175155
// Enqueue with a higher priority (lower number = higher priority)
176-
handle3, err := Enqueue[string, string](clientCtx, GenericEnqueueOptions[string]{
177-
WorkflowName: "PriorityWorkflow",
178-
QueueName: priorityQueue.Name,
179-
WorkflowInput: "ghi",
180-
Priority: 1,
181-
ApplicationVersion: serverCtx.GetApplicationVersion(),
182-
})
156+
handle3, err := Enqueue[string, string](clientCtx, priorityQueue.Name, "PriorityWorkflow", "ghi",
157+
WithEnqueuePriority(1),
158+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
183159
require.NoError(t, err, "failed to enqueue workflow with priority 1")
184160

185161
// Get results
@@ -212,25 +188,17 @@ func TestEnqueue(t *testing.T) {
212188
wfid2 := "client-dedup-wf2"
213189

214190
// First workflow with deduplication ID - should succeed
215-
handle1, err := Enqueue[wfInput, string](clientCtx, GenericEnqueueOptions[wfInput]{
216-
WorkflowName: "ServerWorkflow",
217-
QueueName: queue.Name,
218-
WorkflowID: wfid1,
219-
DeduplicationID: dedupID,
220-
WorkflowInput: wfInput{Input: "test-input"},
221-
ApplicationVersion: serverCtx.GetApplicationVersion(),
222-
})
191+
handle1, err := Enqueue[wfInput, string](clientCtx, queue.Name, "ServerWorkflow", wfInput{Input: "test-input"},
192+
WithEnqueueWorkflowID(wfid1),
193+
WithEnqueueDeduplicationID(dedupID),
194+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
223195
require.NoError(t, err, "failed to enqueue first workflow with deduplication ID")
224196

225197
// Second workflow with same deduplication ID but different workflow ID - should fail
226-
_, err = Enqueue[wfInput, string](clientCtx, GenericEnqueueOptions[wfInput]{
227-
WorkflowName: "ServerWorkflow",
228-
QueueName: queue.Name,
229-
WorkflowID: wfid2,
230-
DeduplicationID: dedupID,
231-
WorkflowInput: wfInput{Input: "test-input"},
232-
ApplicationVersion: serverCtx.GetApplicationVersion(),
233-
})
198+
_, err = Enqueue[wfInput, string](clientCtx, queue.Name, "ServerWorkflow", wfInput{Input: "test-input"},
199+
WithEnqueueWorkflowID(wfid2),
200+
WithEnqueueDeduplicationID(dedupID),
201+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
234202
require.Error(t, err, "expected error when enqueueing workflow with same deduplication ID")
235203

236204
// Check that it's the correct error type and message
@@ -242,22 +210,14 @@ func TestEnqueue(t *testing.T) {
242210
assert.Contains(t, err.Error(), expectedMsgPart, "expected error message to contain deduplication information")
243211

244212
// Third workflow with different deduplication ID - should succeed
245-
handle3, err := Enqueue[wfInput, string](clientCtx, GenericEnqueueOptions[wfInput]{
246-
WorkflowName: "ServerWorkflow",
247-
QueueName: queue.Name,
248-
DeduplicationID: "different-dedup-id",
249-
WorkflowInput: wfInput{Input: "test-input"},
250-
ApplicationVersion: serverCtx.GetApplicationVersion(),
251-
})
213+
handle3, err := Enqueue[wfInput, string](clientCtx, queue.Name, "ServerWorkflow", wfInput{Input: "test-input"},
214+
WithEnqueueDeduplicationID("different-dedup-id"),
215+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
252216
require.NoError(t, err, "failed to enqueue workflow with different deduplication ID")
253217

254218
// Fourth workflow without deduplication ID - should succeed
255-
handle4, err := Enqueue[wfInput, string](clientCtx, GenericEnqueueOptions[wfInput]{
256-
WorkflowName: "ServerWorkflow",
257-
QueueName: queue.Name,
258-
WorkflowInput: wfInput{Input: "test-input"},
259-
ApplicationVersion: serverCtx.GetApplicationVersion(),
260-
})
219+
handle4, err := Enqueue[wfInput, string](clientCtx, queue.Name, "ServerWorkflow", wfInput{Input: "test-input"},
220+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
261221
require.NoError(t, err, "failed to enqueue workflow without deduplication ID")
262222

263223
// Wait for all successful workflows to complete
@@ -274,14 +234,10 @@ func TestEnqueue(t *testing.T) {
274234
assert.Equal(t, "processed: test-input", result4)
275235

276236
// After first workflow completes, we should be able to enqueue with same deduplication ID
277-
handle5, err := Enqueue[wfInput, string](clientCtx, GenericEnqueueOptions[wfInput]{
278-
WorkflowName: "ServerWorkflow",
279-
QueueName: queue.Name,
280-
WorkflowID: wfid2, // Reuse the workflow ID that failed before
281-
DeduplicationID: dedupID, // Same deduplication ID as first workflow
282-
WorkflowInput: wfInput{Input: "test-input"},
283-
ApplicationVersion: serverCtx.GetApplicationVersion(),
284-
})
237+
handle5, err := Enqueue[wfInput, string](clientCtx, queue.Name, "ServerWorkflow", wfInput{Input: "test-input"},
238+
WithEnqueueWorkflowID(wfid2), // Reuse the workflow ID that failed before
239+
WithEnqueueDeduplicationID(dedupID), // Same deduplication ID as first workflow
240+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
285241
require.NoError(t, err, "failed to enqueue workflow with same dedup ID after completion")
286242

287243
result5, err := handle5.GetResult()
@@ -366,13 +322,9 @@ func TestCancelResume(t *testing.T) {
366322
workflowID := "test-cancel-resume-workflow"
367323

368324
// Start the workflow - it will execute step one and then wait
369-
handle, err := Enqueue[int, int](clientCtx, GenericEnqueueOptions[int]{
370-
WorkflowName: "CancelResumeWorkflow",
371-
QueueName: queue.Name,
372-
WorkflowID: workflowID,
373-
WorkflowInput: input,
374-
ApplicationVersion: serverCtx.GetApplicationVersion(),
375-
})
325+
handle, err := Enqueue[int, int](clientCtx, queue.Name, "CancelResumeWorkflow", input,
326+
WithEnqueueWorkflowID(workflowID),
327+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
376328
require.NoError(t, err, "failed to enqueue workflow from client")
377329

378330
// Wait for workflow to signal it has started and step one completed
@@ -435,14 +387,10 @@ func TestCancelResume(t *testing.T) {
435387
workflowTimeout := 2 * time.Second
436388

437389
// Start the workflow with a 2-second timeout
438-
handle, err := Enqueue[string, string](clientCtx, GenericEnqueueOptions[string]{
439-
WorkflowName: "TimeoutBlockingWorkflow",
440-
QueueName: queue.Name,
441-
WorkflowID: workflowID,
442-
WorkflowInput: "timeout-test",
443-
WorkflowTimeout: workflowTimeout,
444-
ApplicationVersion: serverCtx.GetApplicationVersion(),
445-
})
390+
handle, err := Enqueue[string, string](clientCtx, queue.Name, "TimeoutBlockingWorkflow", "timeout-test",
391+
WithEnqueueWorkflowID(workflowID),
392+
WithEnqueueTimeout(workflowTimeout),
393+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
446394
require.NoError(t, err, "failed to enqueue timeout blocking workflow")
447395

448396
// Wait 500ms (well before the timeout expires)
@@ -615,13 +563,9 @@ func TestForkWorkflow(t *testing.T) {
615563
originalWorkflowID := "original-workflow-fork-test"
616564

617565
// 1. Run the entire workflow first and check counters are 1
618-
handle, err := Enqueue[string, string](clientCtx, GenericEnqueueOptions[string]{
619-
WorkflowName: "ParentWorkflow",
620-
QueueName: queue.Name,
621-
WorkflowID: originalWorkflowID,
622-
WorkflowInput: "test",
623-
ApplicationVersion: serverCtx.GetApplicationVersion(),
624-
})
566+
handle, err := Enqueue[string, string](clientCtx, queue.Name, "ParentWorkflow", "test",
567+
WithEnqueueWorkflowID(originalWorkflowID),
568+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
625569
require.NoError(t, err, "failed to enqueue original workflow")
626570

627571
// Wait for the original workflow to complete
@@ -758,27 +702,19 @@ func TestListWorkflows(t *testing.T) {
758702
if i < 5 {
759703
// First 5 workflows: use prefix "test-batch-" and succeed
760704
workflowID = fmt.Sprintf("test-batch-%d", i)
761-
handle, err = Enqueue[testInput, string](clientCtx, GenericEnqueueOptions[testInput]{
762-
WorkflowName: "SimpleWorkflow",
763-
QueueName: queue.Name,
764-
WorkflowID: workflowID,
765-
WorkflowInput: testInput{Value: i, ID: fmt.Sprintf("success-%d", i)},
766-
ApplicationVersion: serverCtx.GetApplicationVersion(),
767-
})
705+
handle, err = Enqueue[testInput, string](clientCtx, queue.Name, "SimpleWorkflow", testInput{Value: i, ID: fmt.Sprintf("success-%d", i)},
706+
WithEnqueueWorkflowID(workflowID),
707+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
768708
} else {
769709
// Last 5 workflows: use prefix "test-other-" and some will fail
770710
workflowID = fmt.Sprintf("test-other-%d", i)
771711
value := i
772712
if i >= 8 {
773713
value = -i // These will fail
774714
}
775-
handle, err = Enqueue[testInput, string](clientCtx, GenericEnqueueOptions[testInput]{
776-
WorkflowName: "SimpleWorkflow",
777-
QueueName: queue.Name,
778-
WorkflowID: workflowID,
779-
WorkflowInput: testInput{Value: value, ID: fmt.Sprintf("test-%d", i)},
780-
ApplicationVersion: serverCtx.GetApplicationVersion(),
781-
})
715+
handle, err = Enqueue[testInput, string](clientCtx, queue.Name, "SimpleWorkflow", testInput{Value: value, ID: fmt.Sprintf("test-%d", i)},
716+
WithEnqueueWorkflowID(workflowID),
717+
WithEnqueueApplicationVersion(serverCtx.GetApplicationVersion()))
782718
}
783719

784720
require.NoError(t, err, "failed to enqueue workflow %d", i)

0 commit comments

Comments
 (0)