Skip to content

Commit

Permalink
Switch to using github.com/gomodule/redigo/redis (#98)
Browse files Browse the repository at this point in the history
Issue #94
  • Loading branch information
peterhellberg authored and shdunning committed May 21, 2018
1 parent 72c8f57 commit 968bd6a
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 69 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To enqueue jobs, you need to make an Enqueuer with a redis namespace and a redig
package main

import (
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
"github.com/gocraft/work"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ In order to process jobs, you'll need to make a WorkerPool. Add middleware and j
package main

import (
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
"github.com/gocraft/work"
"os"
"os/signal"
Expand Down Expand Up @@ -246,11 +246,11 @@ You'll see a view that looks like this:
### Processing a job

* To process a job, a worker will execute a Lua script to atomically move a job its queue to an in-progress queue.
* A job is dequeued and moved to in-progress if the job queue is not paused and the number of active jobs does not exceed concurrency limit for the job type
* A job is dequeued and moved to in-progress if the job queue is not paused and the number of active jobs does not exceed concurrency limit for the job type
* The worker will then run the job and increment the job lock. The job will either finish successfully or result in an error or panic.
* If the process completely crashes, the reaper will eventually find it in its in-progress queue and requeue it.
* If the job is successful, we'll simply remove the job from the in-progress queue.
* If the job returns an error or panic, we'll see how many retries a job has left. If it doesn't have any, we'll move it to the dead queue. If it has retries left, we'll consume a retry and add the job to the retry queue.
* If the job returns an error or panic, we'll see how many retries a job has left. If it doesn't have any, we'll move it to the dead queue. If it has retries left, we'll consume a retry and add the job to the retry queue.

### Workers and WorkerPools

Expand Down
7 changes: 4 additions & 3 deletions benches/bench_goworker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"github.com/benmanns/goworker"
"github.com/garyburd/redigo/redis"
"github.com/gocraft/health"
"os"
"sync/atomic"
"time"

"github.com/benmanns/goworker"
"github.com/gocraft/health"
"github.com/gomodule/redigo/redis"
)

func myJob(queue string, args ...interface{}) error {
Expand Down
6 changes: 3 additions & 3 deletions benches/bench_goworkers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/gocraft/health"
"github.com/jrallison/go-workers"
"os"
"sync/atomic"
"time"

"github.com/gocraft/health"
"github.com/gomodule/redigo/redis"
)

func myJob(m *workers.Msg) {
Expand Down
11 changes: 6 additions & 5 deletions benches/bench_jobs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"github.com/albrow/jobs"
"github.com/garyburd/redigo/redis"
"github.com/gocraft/health"
"os"
"sync/atomic"
"time"

"github.com/albrow/jobs"
"github.com/gocraft/health"
"github.com/gomodule/redigo/redis"
)

var namespace = "jobs"
Expand Down Expand Up @@ -51,8 +52,8 @@ func main() {

job = stream.NewJob("run_all")
pool, err := jobs.NewPool(&jobs.PoolConfig{
// NumWorkers: 1000,
// BatchSize: 3000,
// NumWorkers: 1000,
// BatchSize: 3000,
})
if err != nil {
panic(err)
Expand Down
7 changes: 4 additions & 3 deletions benches/bench_work/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/gocraft/health"
"github.com/gocraft/work"
"os"
"sync/atomic"
"time"

"github.com/gocraft/health"
"github.com/gocraft/work"
"github.com/gomodule/redigo/redis"
)

var namespace = "bench_test"
Expand Down
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package work

import (
"fmt"
"github.com/garyburd/redigo/redis"
"sort"
"strconv"
"strings"

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

// ErrNotDeleted is returned by functions that delete jobs to indicate that although the redis commands were successful,
Expand Down
5 changes: 3 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package work

import (
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/gomodule/redigo/redis"
"github.com/stretchr/testify/assert"
)

type TestContext struct{}
Expand Down
5 changes: 3 additions & 2 deletions cmd/workenqueue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/gocraft/work"
"os"
"time"

"github.com/gocraft/work"
"github.com/gomodule/redigo/redis"
)

var redisHostPort = flag.String("redis", ":6379", "redis hostport")
Expand Down
5 changes: 3 additions & 2 deletions cmd/workfakedata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"flag"
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/gocraft/work"
"math/rand"
"time"

"github.com/gocraft/work"
"github.com/gomodule/redigo/redis"
)

var redisHostPort = flag.String("redis", ":6379", "redis hostport")
Expand Down
2 changes: 1 addition & 1 deletion cmd/workwebui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strconv"
"time"

"github.com/garyburd/redigo/redis"
"github.com/gocraft/work/webui"
"github.com/gomodule/redigo/redis"
)

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

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

const (
Expand Down
5 changes: 3 additions & 2 deletions dead_pool_reaper_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package work

import (
"github.com/garyburd/redigo/redis"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/gomodule/redigo/redis"
"github.com/stretchr/testify/assert"
)

func TestDeadPoolReaper(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion enqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"sync"
"time"

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

// Enqueuer can enqueue jobs.
Expand Down
4 changes: 2 additions & 2 deletions heartbeater.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package work

import (
// "fmt"
"github.com/garyburd/redigo/redis"
"os"
"sort"
"strings"
"time"

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

const (
Expand Down
6 changes: 3 additions & 3 deletions heartbeater_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package work

import (
// "fmt"
"github.com/garyburd/redigo/redis"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/gomodule/redigo/redis"
"github.com/stretchr/testify/assert"
)

func TestHeartbeater(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions identifier_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package work

import (
"testing"
)
import "testing"

func TestMakeIdentifier(t *testing.T) {
id := makeIdentifier()
Expand Down
3 changes: 2 additions & 1 deletion job_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package work

import (
"github.com/stretchr/testify/assert"
"math"
"testing"

"github.com/stretchr/testify/assert"
)

func TestJobArgumentExtraction(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions log.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package work

import (
"fmt"
)
import "fmt"

func logError(key string, err error) {
fmt.Printf("ERROR: %s - %s\n", key, err.Error())
Expand Down
3 changes: 2 additions & 1 deletion observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package work
import (
"encoding/json"
"fmt"
"github.com/garyburd/redigo/redis"
"time"

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

// An observer observes a single worker. Each worker has its own observer.
Expand Down
6 changes: 3 additions & 3 deletions observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package work

import (
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/stretchr/testify/assert"
"testing"
// "time"

"github.com/gomodule/redigo/redis"
"github.com/stretchr/testify/assert"
)

func TestObserverStarted(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions periodic_enqueuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package work

import (
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/robfig/cron"
"math/rand"
"time"

"github.com/gomodule/redigo/redis"
"github.com/robfig/cron"
)

const (
Expand Down
7 changes: 4 additions & 3 deletions periodic_enqueuer_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package work

import (
"github.com/garyburd/redigo/redis"
"github.com/robfig/cron"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/gomodule/redigo/redis"
"github.com/robfig/cron"
"github.com/stretchr/testify/assert"
)

func TestPeriodicEnqueuer(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion priority_sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package work

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestPrioritySampler(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions requeuer.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package work

import (
// "encoding/json"
"fmt"
"time"

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

type requeuer struct {
Expand Down
7 changes: 2 additions & 5 deletions requeuer_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package work

import (
// "github.com/garyburd/redigo/redis"
"github.com/stretchr/testify/assert"
"testing"
// "fmt"
// "time"
// "os"

"github.com/stretchr/testify/assert"
)

func TestRequeue(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package work

import (
"fmt"
"github.com/stretchr/testify/assert"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRunBasicMiddleware(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions time.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package work

import (
"time"
)
import "time"

var nowMock int64

Expand Down
2 changes: 1 addition & 1 deletion webui/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"sync"

"github.com/braintree/manners"
"github.com/garyburd/redigo/redis"
"github.com/gocraft/web"
"github.com/gocraft/work"
"github.com/gocraft/work/webui/internal/assets"
"github.com/gomodule/redigo/redis"
)

// Server implements an HTTP server which exposes a JSON API to view and manage gocraft/work items.
Expand Down
Loading

0 comments on commit 968bd6a

Please sign in to comment.