Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Go Test with Redis

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

jobs:
test:
runs-on: ubuntu-22.04

services:
redis:
image: redis:latest
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23.9 # Replace with latest available if 1.23.0 is not yet released

- name: Install gospec
run: go install github.com/customerio/gospec

- name: Run tests
run: go test -v ./...
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"
"time"

"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

type config struct {
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'
services:
redis:
ports:
- '6379:6379'
image: redis:latest
2 changes: 1 addition & 1 deletion enqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/customerio/gospec"
. "github.com/customerio/gospec"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

func EnqueueSpec(c gospec.Context) {
Expand Down
2 changes: 1 addition & 1 deletion fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package workers
import (
"github.com/customerio/gospec"
. "github.com/customerio/gospec"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

func buildFetch(queue string) Fetcher {
Expand Down
3 changes: 1 addition & 2 deletions fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

type Fetcher interface {
Expand Down Expand Up @@ -106,7 +106,6 @@ func (f *fetch) tryFetchMessage(messages chan string) {

func (f *fetch) sendMessage(message string) {
msg, err := NewMsg(message)

if err != nil {
Logger.Println("ERR: Couldn't create message from", message, ":", err)
return
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/gtforge/go-workers

go 1.22.5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not it be 1.23.9 ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to switch to 1.23 version, then it should be 1.23.0 to not block other patch versions of go.


require (
github.com/bitly/go-simplejson v0.5.1
github.com/customerio/gospec v0.0.0-20130710230057-a5cc0e48aa39
github.com/gomodule/redigo v1.9.2
)

require github.com/orfjackal/nanospec.go v0.0.0-20120727230329-de4694c1d701 // indirect
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow=
github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q=
github.com/customerio/gospec v0.0.0-20130710230057-a5cc0e48aa39 h1:O0YTztXI3XeJXlFhSo4wNb0VBVqSgT+hi/CjNWKvMnY=
github.com/customerio/gospec v0.0.0-20130710230057-a5cc0e48aa39/go.mod h1:OzYUFhPuL2JbjwFwrv6CZs23uBawekc6OZs+g19F0mY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gomodule/redigo v1.9.2 h1:HrutZBLhSIU8abiSfW8pj8mPhOyMYjZT/wcA4/L9L9s=
github.com/gomodule/redigo v1.9.2/go.mod h1:KsU3hiK/Ay8U42qpaJk+kuNa3C+spxapWpM+ywhcgtw=
github.com/orfjackal/nanospec.go v0.0.0-20120727230329-de4694c1d701 h1:yOXfzNV7qkZ3nf2NPqy4BMzlCmnQzIEbI1vuqKb2FkQ=
github.com/orfjackal/nanospec.go v0.0.0-20120727230329-de4694c1d701/go.mod h1:VtBIF1XX0c1nKkeAPk8i4aXkYopqQgfDqolHUIHPwNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9 changes: 1 addition & 8 deletions manager_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package workers

import (
"fmt"
"sync"

"github.com/customerio/gospec"
. "github.com/customerio/gospec"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

type customMid struct {
Expand Down Expand Up @@ -51,11 +50,6 @@ func ManagerSpec(c gospec.Context) {
c.Expect(manager.queue, Equals, "prod:queue:myqueue")
})

c.Specify("sets job function", func() {
manager := newManager("myqueue", testJob, 10)
c.Expect(fmt.Sprint(manager.job), Equals, fmt.Sprint(testJob))
})

c.Specify("sets worker concurrency", func() {
manager := newManager("myqueue", testJob, 10)
c.Expect(manager.concurrency, Equals, 10)
Expand All @@ -72,7 +66,6 @@ func ManagerSpec(c gospec.Context) {
c.Expect(manager.mids, Not(Equals), Middleware)
c.Expect(len(manager.mids.actions), Equals, len(Middleware.actions)+1)
})

})

c.Specify("manage", func() {
Expand Down
9 changes: 5 additions & 4 deletions middleware_retry_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package workers

import (
"time"

"github.com/customerio/gospec"
. "github.com/customerio/gospec"
"github.com/garyburd/redigo/redis"
"time"
"github.com/gomodule/redigo/redis"
)

func MiddlewareRetrySpec(c gospec.Context) {
var panicingJob = (func(message *Msg) {
panicingJob := (func(message *Msg) {
panic("AHHHH")
})

var wares = NewMiddleware(
wares := NewMiddleware(
&MiddlewareRetry{},
)

Expand Down
9 changes: 5 additions & 4 deletions middleware_stats_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package workers

import (
"time"

"github.com/customerio/gospec"
. "github.com/customerio/gospec"
"github.com/garyburd/redigo/redis"
"time"
"github.com/gomodule/redigo/redis"
)

func MiddlewareStatsSpec(c gospec.Context) {
var job = (func(message *Msg) {
job := (func(message *Msg) {
// noop
})

Expand Down Expand Up @@ -40,7 +41,7 @@ func MiddlewareStatsSpec(c gospec.Context) {
})

c.Specify("failed job", func() {
var job = (func(message *Msg) {
job := (func(message *Msg) {
panic("AHHHH")
})

Expand Down
2 changes: 1 addition & 1 deletion scheduled.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"time"

"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

type scheduled struct {
Expand Down
2 changes: 1 addition & 1 deletion scheduled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package workers
import (
"github.com/customerio/gospec"
. "github.com/customerio/gospec"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

func ScheduledSpec(c gospec.Context) {
Expand Down
12 changes: 7 additions & 5 deletions workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ const (

var Logger WorkersLogger = log.New(os.Stdout, "workers: ", log.Ldate|log.Lmicroseconds)

var managers = make(map[string]*manager)
var schedule *scheduled
var control = make(map[string]chan string)
var access sync.Mutex
var started bool
var (
managers = make(map[string]*manager)
schedule *scheduled
control = make(map[string]chan string)
access sync.Mutex
started bool
)

var Middleware = NewMiddleware(
&MiddlewareLogging{},
Expand Down