From f78568407be7b2b02363051fb36dd49cf96aa317 Mon Sep 17 00:00:00 2001 From: Ilya Solo Date: Thu, 15 May 2025 14:38:13 +0300 Subject: [PATCH 1/7] Replace old redigo --- config.go | 2 +- enqueue_test.go | 2 +- fetch_test.go | 2 +- fetcher.go | 3 +-- manager_test.go | 3 +-- middleware_retry_test.go | 9 +++++---- middleware_stats_test.go | 9 +++++---- scheduled.go | 2 +- scheduled_test.go | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/config.go b/config.go index f93ac94..15b3e5b 100644 --- a/config.go +++ b/config.go @@ -4,7 +4,7 @@ import ( "strconv" "time" - "github.com/garyburd/redigo/redis" + "github.com/gomodule/redigo/redis" ) type config struct { diff --git a/enqueue_test.go b/enqueue_test.go index e3a2707..3980941 100644 --- a/enqueue_test.go +++ b/enqueue_test.go @@ -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) { diff --git a/fetch_test.go b/fetch_test.go index 37e3fcc..3a355f2 100644 --- a/fetch_test.go +++ b/fetch_test.go @@ -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 { diff --git a/fetcher.go b/fetcher.go index c3b3b55..44aca90 100644 --- a/fetcher.go +++ b/fetcher.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/garyburd/redigo/redis" + "github.com/gomodule/redigo/redis" ) type Fetcher interface { @@ -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 diff --git a/manager_test.go b/manager_test.go index 89a3dcd..86d6831 100644 --- a/manager_test.go +++ b/manager_test.go @@ -6,7 +6,7 @@ import ( "github.com/customerio/gospec" . "github.com/customerio/gospec" - "github.com/garyburd/redigo/redis" + "github.com/gomodule/redigo/redis" ) type customMid struct { @@ -72,7 +72,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() { diff --git a/middleware_retry_test.go b/middleware_retry_test.go index a17cf7a..0638a23 100644 --- a/middleware_retry_test.go +++ b/middleware_retry_test.go @@ -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{}, ) diff --git a/middleware_stats_test.go b/middleware_stats_test.go index 46b53a8..6ca75fa 100644 --- a/middleware_stats_test.go +++ b/middleware_stats_test.go @@ -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 }) @@ -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") }) diff --git a/scheduled.go b/scheduled.go index a7b08fa..a84a849 100644 --- a/scheduled.go +++ b/scheduled.go @@ -4,7 +4,7 @@ import ( "strings" "time" - "github.com/garyburd/redigo/redis" + "github.com/gomodule/redigo/redis" ) type scheduled struct { diff --git a/scheduled_test.go b/scheduled_test.go index d292a77..af591f4 100644 --- a/scheduled_test.go +++ b/scheduled_test.go @@ -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) { From 63cc4fccca7680311282d95875cb0f766a444764 Mon Sep 17 00:00:00 2001 From: Ilya Solo Date: Thu, 15 May 2025 14:39:30 +0300 Subject: [PATCH 2/7] Fixed --- workers.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/workers.go b/workers.go index 3b118cb..8d0574e 100644 --- a/workers.go +++ b/workers.go @@ -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{}, @@ -37,6 +39,7 @@ func Process(queue string, job jobFunc, concurrency int, mids ...Action) { func Run() { Start() + go handleSignals() waitForExit() } From 354053a0e2d13d3a1f42bf4ebf8f1d5dc321377c Mon Sep 17 00:00:00 2001 From: Ilya Solo Date: Thu, 15 May 2025 15:13:52 +0300 Subject: [PATCH 3/7] Fixed tests --- .travis.yml | 2 +- docker-compose.yml | 6 ++++++ go.mod | 11 +++++++++++ go.sum | 16 ++++++++++++++++ manager_test.go | 6 ------ 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 docker-compose.yml create mode 100644 go.mod create mode 100644 go.sum diff --git a/.travis.yml b/.travis.yml index 141ea53..0bbcdb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.7 + - 1.23.0 script: - go get github.com/customerio/gospec diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..31c686c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3' +services: + redis: + ports: + - '6379:6379' + image: redis:latest diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..44ef75f --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/gtforge/go-workers + +go 1.22.5 + +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 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..33bd34f --- /dev/null +++ b/go.sum @@ -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= diff --git a/manager_test.go b/manager_test.go index 86d6831..5cbdd12 100644 --- a/manager_test.go +++ b/manager_test.go @@ -1,7 +1,6 @@ package workers import ( - "fmt" "sync" "github.com/customerio/gospec" @@ -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) From 10628d89ee310c67ff7115330056d82a97b9ace8 Mon Sep 17 00:00:00 2001 From: Ilya Solo Date: Thu, 15 May 2025 15:19:31 +0300 Subject: [PATCH 4/7] FIxed test failure --- workers.go | 1 - 1 file changed, 1 deletion(-) diff --git a/workers.go b/workers.go index 8d0574e..cb22838 100644 --- a/workers.go +++ b/workers.go @@ -39,7 +39,6 @@ func Process(queue string, job jobFunc, concurrency int, mids ...Action) { func Run() { Start() - go handleSignals() waitForExit() } From 97e1dc4985ea16ebc1a424e5cc59debe9f40dc0f Mon Sep 17 00:00:00 2001 From: Ilya Solo Date: Thu, 15 May 2025 15:51:27 +0300 Subject: [PATCH 5/7] Added github actions --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9e0d3ad --- /dev/null +++ b/.github/workflows/ci.yml @@ -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@latest + + - name: Run tests + run: go test -v ./... From 49cdc37058c36dba2a789c9de044b4b6f7aad00b Mon Sep 17 00:00:00 2001 From: Ilya Solo Date: Thu, 15 May 2025 15:53:48 +0300 Subject: [PATCH 6/7] Fixed github actions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e0d3ad..22b9648 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: 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@latest + run: go install github.com/customerio/gospec - name: Run tests run: go test -v ./... From 337fa6708ebf5797ec27a199e6ee6990eb7a5447 Mon Sep 17 00:00:00 2001 From: Ilya Solo Date: Thu, 15 May 2025 15:55:19 +0300 Subject: [PATCH 7/7] Removed travis --- .travis.yml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0bbcdb8..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: go - -go: - - 1.23.0 - -script: - - go get github.com/customerio/gospec - - go test -v - -services: - - redis-server