Skip to content

Commit

Permalink
Add workflows badge
Browse files Browse the repository at this point in the history
  • Loading branch information
Stashchenko committed May 20, 2020
1 parent ee69b36 commit 31168de
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 36 deletions.
105 changes: 74 additions & 31 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,80 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

on: [push, pull_request]
name: test and build
jobs:

build:
name: Build
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
- name: Checkout code
uses: actions/checkout@v1
- name: Install golangci-lint
run: |
go get github.com/golangci/golangci-lint/cmd/golangci-lint
- name: Run linters
run: |
export PATH=$PATH:$(go env GOPATH)/bin && golangci-lint --tests=false -E bodyclose,misspell,gocyclo,dupl,gofmt,golint,unconvert,depguard,gocritic,funlen,interfacer run
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
test:
strategy:
matrix:
go-version: [1.12.x, 1.13.x]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Run tests
run: go test -v -covermode=count

- name: Build
run: go build -v .
coverage:
runs-on: ubuntu-latest
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v1
with:
go-version: 1.13.x
- name: Checkout code
uses: actions/checkout@v1
- name: Calc coverage
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go test -v -covermode=count -coverprofile=coverage.out
- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.0
with:
infile: coverage.out
outfile: coverage.lcov
- name: Coveralls
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov

- name: Test
run: go test -v .
build:
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
- name: Checkout code
uses: actions/checkout@v1
- name: build
run: |
export GO111MODULE=on
GOOS=linux GOARCH=amd64 go build -o bin/ci-test-linux-amd64
- name: upload artifacts
uses: actions/upload-artifact@master
with:
name: binaries
path: bin/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# sqs-worker

![Test&Build](https://github.com/Stashchenko/sqs-worker/workflows/test%20and%20build/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/Stashchenko/sqs-worker/badge.svg?branch=master)](https://coveralls.io/github/Stashchenko/sqs-worker?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/Stashchenko/sqs-worker)](https://goreportcard.com/report/github.com/Stashchenko/sqs-worker)

GoLang SQS Queue Worker using the AWS SDK:

`go get github.com/Stashchenko/sqs-worker`
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
func stopGracefully(cancel context.CancelFunc) {
// Wait for a signal to quit:
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, os.Kill, syscall.SIGTERM)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
<-signalChan
fmt.Println("Stopping sqs workers gracefully...")
cancel()
Expand Down
9 changes: 6 additions & 3 deletions message_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestStart(t *testing.T) {
queue := newJobMessageQueue(config, mockSQSClient)

ctx, cancel := contextAndCancel()
defer cancel()

t.Run("the queue has correct configuration", func(t *testing.T) {
assert.Equal(t, queue.config.QueueURL, queueURL, "QueueURL has been set properly")
Expand All @@ -71,13 +70,16 @@ func TestStart(t *testing.T) {

t.Run("Should put a job to the job queue", func(t1 *testing.T) {
go queue.listen(ctx)
defer cancel()

clientParams := buildClientParams()
deleteInput := &sqs.DeleteMessageInput{QueueUrl: clientParams.QueueUrl}

t1.Run("the queue successfully sends a message", func(t *testing.T) {
mockSQSClient.On("ReceiveMessage", clientParams).Return()

jobQ := <-queue.GetJobs()
jobQ, ok := <-queue.GetJobs()
assert.Equal(t, ok, true)
assert.IsType(t, jobQ, &job{})
assert.IsType(t, jobQ.Message, sqsMessage)

Expand All @@ -88,7 +90,8 @@ func TestStart(t *testing.T) {
mockSQSClient.On("ReceiveMessage", clientParams).Return()
mockSQSClient.On("DeleteMessage", deleteInput).Return()

jobQ := <-queue.GetJobs()
jobQ, ok := <-queue.GetJobs()
assert.Equal(t, ok, true)
err := queue.DeleteMessage(jobQ.Message.ReceiptHandle)

assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (w *Worker) processJob(job *job, h Handler) error {
}
w.log.Debug(fmt.Sprintf("worker %d: deleted message from queue: %s", w.id, aws.StringValue(job.Message.MessageId)))

job.Duration = time.Now().Sub(job.StartedAt)
job.Duration = time.Since(job.StartedAt)
w.log.Debug(fmt.Sprintf("worker %d: processed job in: %s", w.id, job.Duration))
return nil
}

0 comments on commit 31168de

Please sign in to comment.