Skip to content

Commit 725ff6b

Browse files
authored
Merge pull request #1 from Pod-Point/PAR-update-fork
chore: update fork with changes from formigo
2 parents 9a85c04 + dd877c2 commit 725ff6b

File tree

17 files changed

+559
-109
lines changed

17 files changed

+559
-109
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- uses: actions/setup-go@v4
2020
with:
21-
go-version: '1.22'
21+
go-version-file: 'go.mod'
2222
cache: false
2323
- name: golangci-lint
2424
uses: golangci/golangci-lint-action@v3
@@ -32,7 +32,7 @@ jobs:
3232
- name: govulncheck
3333
uses: golang/govulncheck-action@v1
3434
with:
35-
go-version-input: '~1.22.0'
35+
go-version-file: 'go.mod'
3636
check-latest: true
3737

3838
commitlint:
@@ -57,4 +57,4 @@ jobs:
5757

5858
- name: Validate PR commits with commitlint
5959
if: github.event_name == 'pull_request'
60-
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
60+
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
permissions:
8+
contents: read # for checkout
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write # to be able to publish a GitHub release
16+
issues: write # to be able to comment on released issues
17+
pull-requests: write # to be able to comment on released pull requests
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: "lts/*"
27+
- name: Install dependencies
28+
run: npm install --save-dev @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/changelog @semantic-release/git @semantic-release/github
29+
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
30+
run: npm audit signatures
31+
- name: Release
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
run: npx semantic-release

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-go@v4
15+
with:
16+
go-version-file: 'go.mod'
17+
cache: false
18+
- name: Run tests
19+
run: go test ./...

.releaserc.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
branches:
3+
- main
4+
preset: "angular"
5+
tagFormat: "v${version}"
6+
plugins:
7+
- "@semantic-release/commit-analyzer"
8+
- "@semantic-release/release-notes-generator"
9+
- "@semantic-release/github"
10+
11+
verifyConditions:
12+
- "@semantic-release/github"
13+
analyzeCommits:
14+
- path: "@semantic-release/commit-analyzer"
15+
releaseRules:
16+
- type: "feat"
17+
release: "patch"
18+
- type: "hotfix"
19+
release: "patch"
20+
- type: "patch"
21+
release: "patch"
22+
- type: "minor"
23+
release: "minor"
24+
- type: "breaking"
25+
release: "major"
26+
generateNotes:
27+
- path: "@semantic-release/release-notes-generator"
28+
writerOpts:
29+
groupBy: "type"
30+
commitGroupsSort:
31+
- "feat"
32+
- "perf"
33+
- "fix"
34+
commitsSort: "header"
35+
types:
36+
- type: "feat"
37+
- section: "Features"
38+
# Tracked bug fix with a hotfix branch
39+
- type: "hotfix"
40+
- section: "Bug Fixes"
41+
# Uninmportent fix (CI testing, etc)
42+
- type: "fix"
43+
- hidden: true
44+
- type: "chore"
45+
- hidden: true
46+
- type: "docs"
47+
- hidden: true
48+
- type: "doc"
49+
- hidden: true
50+
- type: "style"
51+
- hidden: true
52+
- type: "refactor"
53+
- hidden: true
54+
- type: "perf"
55+
- hidden: true
56+
- type: "test"
57+
- hidden: true
58+
presetConfig: true
59+
publish:
60+
- path: "@semantic-release/github"
61+
62+
success:
63+
- "@semantic-release/github"
64+
65+
fail:
66+
- "@semantic-release/github"

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Formigo is a powerful and flexible Golang library designed to simplify the proce
66

77
- **Efficient Throughput Management**: it offers optimal throughput management, allowing you to fine-tune the number of Go routines responsible for both polling messages from the queue and processing them. This dynamic control ensures maximum efficiency in various scenarios, making the library highly adaptable to your application's needs.
88

9-
- **Configurable Batch Processing**: it uses powerful batch processing capabilities, enabling you to handle messages efficiently in customizable batches. With the Multiple Message Handler, messages can be processed in batches of a size you define, granting you full control over the processing logic. Moreover, you can adjust the batch buffer size and timeout settings, providing a flexible and optimal solution to process messages under various workloads.
9+
- **Configurable Batch Processing**: it uses powerful batch processing capabilities, enabling you to handle messages efficiently in customizable batches. With the Batch Handler, messages can be processed in batches of a size you define, granting you full control over the processing logic. Moreover, you can adjust the batch buffer size and timeout settings, providing a flexible and optimal solution to process messages under various workloads.
1010

1111
- **Context Cancellation**: Effortlessly stop the QueueWorker by canceling its context. This feature guarantees smooth and controlled termination of the worker whenever required.
1212

@@ -38,7 +38,7 @@ import (
3838
"fmt"
3939
"log"
4040

41-
"github.com/Pod-Point/go-queue-worker"
41+
formigo "github.com/Pod-Point/go-queue-worker"
4242
workerSqs "github.com/Pod-Point/go-queue-worker/clients/sqs"
4343

4444
"github.com/aws/aws-sdk-go-v2/aws"
@@ -72,12 +72,12 @@ func main() {
7272
wkr := formigo.NewWorker(formigo.Configuration{
7373
Client: sqsClient,
7474
Concurrency: 100,
75-
Consumer: formigo.NewSingleMessageConsumer(formigo.SingleMessageConsumerConfiguration{
76-
Handler: func(ctx context.Context, msg interface{}) error {
77-
log.Println("Got Message", msgs)
75+
Consumer: formigo.NewMessageConsumer(formigo.MessageConsumerConfiguration{
76+
Handler: func(ctx context.Context, msg formigo.Message) error {
77+
log.Println("Got Message", msg.Content())
7878

7979
// Assert the type of message to get the body or any other attributes
80-
log.Println("Message body", *msg.(types.Message).Body)
80+
log.Println("Message body", *msg.Content().(types.Message).Body)
8181

8282
return nil
8383
},
@@ -108,7 +108,7 @@ import (
108108
"fmt"
109109
"log"
110110

111-
"github.com/Pod-Point/go-queue-worker"
111+
formigo "github.com/Pod-Point/go-queue-worker"
112112
workerSqs "github.com/Pod-Point/go-queue-worker/clients/sqs"
113113

114114
"github.com/aws/aws-sdk-go-v2/aws"
@@ -142,18 +142,18 @@ func main() {
142142
wkr := formigo.NewWorker(formigo.Configuration{
143143
Client: sqsClient,
144144
Concurrency: 100,
145-
Consumer: formigo.NewMultiMessageConsumer(formigo.MultiMessageConsumerConfiguration{
146-
BufferConfig: formigo.MultiMessageBufferConfiguration{
145+
Consumer: formigo.BatchConsumer(formigo.BatchConsumerConfiguration{
146+
BufferConfig: formigo.BatchBufferConfiguration{
147147
Size: 100,
148148
Timeout: time.Second * 5,
149149
},
150-
Handler: func(ctx context.Context, msgs []interface{}) error {
150+
Handler: func(ctx context.Context, msgs []formigo.Message) error {
151151
log.Printf("Got %d messages to process\n", len(msgs)
152152

153153
// Assert the type of message to get the body or any other attributes
154154

155155
for i, msg := range msgs {
156-
log.Printf("Message %d body: %s", i, *msg.(types.Message).Body)
156+
log.Printf("Message %d body: %s", i, *msg.Content().(types.Message).Body)
157157
}
158158

159159
return nil
@@ -176,13 +176,13 @@ By processing messages in batches, the worker can significantly enhance throughp
176176

177177
## Configuration
178178

179-
| Configuration | Explanation | Default Value |
180-
|-------------- | ----------- | ------------- |
181-
| Client | The client is used for receiving messages from the queue and deleting them once they are processed correctly. This is a required configuration. | None |
182-
| Concurrency | Number of Go routines that process the messages from the Queue. Higher values are useful for slow I/O operations in the consumer's handler. | 100 |
183-
| Retrievers | Number of Go routines that retrieve messages from the Queue. Higher values are helpful for slow networks or when consumers are quicker. | 1 |
184-
| ErrorConfig | Defines the error threshold and interval for worker termination and error reporting function. | None |
185-
| Consumer | The message consumer, either SingleMessageConsumer or MultipleMessageConsumer. | None |
179+
| Configuration | Explanation | Default Value |
180+
|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
181+
| Client | The client is used for receiving messages from the queue and deleting them once they are processed correctly. This is a required configuration. | None |
182+
| Concurrency | Number of Go routines that process the messages from the Queue. Higher values are useful for slow I/O operations in the consumer's handler. | 100 |
183+
| Retrievers | Number of Go routines that retrieve messages from the Queue. Higher values are helpful for slow networks or when consumers are quicker. | 1 |
184+
| ErrorConfig | Defines the error threshold and interval for worker termination and error reporting function. | None |
185+
| Consumer | The message consumer, either MessageConsumer or BatchConsumer. | None |
186186

187187
## License
188188

config.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ type ErrorConfiguration struct {
3333
// Default: 120s.
3434
Period time.Duration
3535

36-
// The error report function
37-
ReportFunc func(err error)
36+
// The error report function, returns a boolean value to decide whether the error counts towards to threshold
37+
ReportFunc func(err error) bool
3838
}
3939

40-
// The MultiMessageBufferConfiguration defines a buffer which is consumed by the worker when either
40+
// The BatchConsumerBufferConfiguration defines a buffer which is consumed by the worker when either
4141
// the buffer is full or the timeout has passed since the first message got added.
42-
type MultiMessageBufferConfiguration struct {
42+
type BatchConsumerBufferConfiguration struct {
4343
// Max number of messages that the buffer can contain.
4444
// Default: 10.
4545
Size int
@@ -52,13 +52,13 @@ type MultiMessageBufferConfiguration struct {
5252
Timeout time.Duration
5353
}
5454

55-
type SingleMessageConsumerConfiguration struct {
56-
Handler singleMessageHandler
55+
type MessageConsumerConfiguration struct {
56+
Handler MessageHandler
5757
}
5858

59-
type MultiMessageConsumerConfiguration struct {
60-
Handler multiMessageHandler
61-
BufferConfig MultiMessageBufferConfiguration
59+
type BatchConsumerConfiguration struct {
60+
Handler BatchHandler
61+
BufferConfig BatchConsumerBufferConfiguration
6262
}
6363

6464
type Configuration struct {
@@ -83,7 +83,7 @@ type Configuration struct {
8383
ErrorConfig ErrorConfiguration
8484

8585
// The messages Consumer.
86-
Consumer consumer
86+
Consumer Consumer
8787

8888
// Configuration for the deleter
8989
DeleterConfig DeleterConfiguration
@@ -107,8 +107,10 @@ func setWorkerConfigValues(config Configuration) Configuration {
107107
}
108108

109109
if config.ErrorConfig.ReportFunc == nil {
110-
config.ErrorConfig.ReportFunc = func(err error) {
110+
config.ErrorConfig.ReportFunc = func(err error) bool {
111111
log.Println("ERROR", err)
112+
113+
return true
112114
}
113115
}
114116

0 commit comments

Comments
 (0)