Skip to content

Commit 2a04345

Browse files
authored
Db retries (#146)
Address #93 This PR adds a `retry` method that can take in another function for retry until a specific condition is met. `retry` can be configured with functional options and has a `retryWithResult` generic counterpart for functions returning a value. All system database methods are now called within `retry` or `retryWithResult`. For example ```go dequeuedWorkflows, err := retryWithResult(ctx, func() ([]dequeuedWorkflow, error) { return ctx.systemDB.dequeueWorkflows(ctx, dequeueWorkflowsInput{ queue: queue, executorID: ctx.executorID, applicationVersion: ctx.applicationVersion, }) }, withRetrierLogger(qr.logger)) ``` retry performs exponential backoff with jitter. It defaults to infinite retries. The default condition for retrying is `isRetryablePGError`, which matches the function returned error with a set of connection errors (postgres codes, pgx connection errors, `net.Error`) Note: in the particular case of RunWorkflow, which does manage transactions, the entire function has to be retried. This is because the transaction object becomes invalid as soon as Commit/Rollback have been called, regardless of whether the operation was successful. See https://github.com/jackc/pgx/blob/61d3c965ad442cc14d6b0e39e0ab3821f3684c03/tx.go#L180 This PR also improves `DBOSError` with the ability to unwrap the underlying error, if any.
1 parent 5501699 commit 2a04345

File tree

11 files changed

+878
-160
lines changed

11 files changed

+878
-160
lines changed

.github/workflows/chaos-tests.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Run Chaos Tests
2+
on:
3+
schedule:
4+
# Runs every hour on the hour
5+
- cron: '0 * * * *'
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
types:
12+
- ready_for_review
13+
- opened
14+
- reopened
15+
- synchronize
16+
workflow_dispatch:
17+
18+
jobs:
19+
chaos-test:
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 60
22+
steps:
23+
- uses: actions/checkout@v5
24+
with:
25+
fetch-depth: 0
26+
fetch-tags: true
27+
28+
- name: Setup Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version: '1.25.x'
32+
33+
- name: Download dependencies
34+
run: go mod download
35+
36+
- name: Install gotestsum
37+
run: go install gotest.tools/gotestsum@latest
38+
39+
- name: Run chaos tests
40+
run: go vet ./... && go test -v -race -timeout 60m -count=1 ./...
41+
working-directory: ./chaos_tests
42+
env:
43+
PGPASSWORD: a!b@c$d()e*_,/:;=?@ff[]22
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ jobs:
4444
with:
4545
go-version: '1.25.x'
4646

47-
- name: Cache Go modules
48-
uses: actions/cache@v4
49-
with:
50-
path: |
51-
~/go/pkg/mod
52-
~/.cache/go-build
53-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
54-
restore-keys: |
55-
${{ runner.os }}-go-
56-
5747
- name: Download dependencies
5848
run: go mod download
5949

0 commit comments

Comments
 (0)