Skip to content

Commit 77538a4

Browse files
author
Alexey Samoylov
authored
Merge pull request #3 from yarcode/beta
Beta
2 parents 8fdfca2 + 5f69c69 commit 77538a4

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

.github/workflows/ci.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- master
9+
- main
10+
- beta*
11+
pull_request:
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-go@v2
20+
with:
21+
go-version: '1.18.3'
22+
23+
- name: Build
24+
run: go build .
25+
26+
- name: Test With Coverage
27+
run: go test -race -v -coverprofile=coverage.txt -covermode=atomic ./...
28+
29+
- name: Upload coverage to Codecov
30+
uses: codecov/codecov-action@v2
31+
32+
- name: Run Vet & Lint
33+
run: |
34+
go vet ./...

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
13+
coverage.txt
1314

1415
# Dependency directories (remove the comment below to include it)
1516
# vendor/

README.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# workerpool
22

3-
[![codecov](https://codecov.io/gh/yarcode/workerpool/branch/master/graph/badge.svg)](https://codecov.io/gh/yarcode/workerpool)
3+
[![codecov](https://codecov.io/gh/yarcode/workerpool/branch/main/graph/badge.svg)](https://codecov.io/gh/yarcode/workerpool)
44
[![golangci](https://golangci.com/badges/github.com/yarcode/workerpool.svg)](https://golangci.com/r/github.com/yarcode/workerpool)
55
[![GoDoc](https://img.shields.io/badge/pkg.go.dev-doc-blue)](http://pkg.go.dev/github.com/yarcode/workerpool)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/yarcode/workerpool)](https://goreportcard.com/report/github.com/yarcode/workerpool)
@@ -12,6 +12,7 @@ Jobs could have contexts, timeouts, rich retry strategies.
1212
## Examples
1313

1414
```golang
15+
1516
pool := New()
1617
pool.Start()
1718

@@ -21,11 +22,28 @@ job := func(ctx context.Context) error {
2122
}
2223

2324
pool.Run(job)
24-
pool.Stop()
25+
2526
```
2627

27-
Output:
28+
### AdvancedUsage
29+
30+
```golang
31+
32+
pool := New()
33+
pool.Start()
34+
35+
job := func(ctx context.Context) error {
36+
//
37+
// some tricky logic goes here
38+
//
39+
40+
return nil
41+
}
42+
// add 3 seconds timeout for a job execution
43+
job = AddTimeout(job, time.Second*3)
44+
// retry job execution withing 5 attempts
45+
job = AddRetry(job, strategy.Limit(5))
46+
47+
pool.Run(job)
2848

29-
```
30-
hello
3149
```

workerpool_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ func ExampleAddLogger() {
174174
pool.Start()
175175

176176
job1 := func(ctx context.Context) error {
177+
time.Sleep(5 * time.Millisecond)
177178
zerolog.Ctx(ctx).Warn().Msg("hello from job1")
178179
return nil
179180
}
180181
job2 := func(ctx context.Context) error {
182+
time.Sleep(10 * time.Millisecond)
181183
zerolog.Ctx(ctx).Warn().Msg("hello from job2")
182184
return nil
183185
}

0 commit comments

Comments
 (0)