Skip to content

Commit

Permalink
Removed the lock functions, lockers moved to locker package. (#6)
Browse files Browse the repository at this point in the history
Used radix as single redis client
Init go module
  • Loading branch information
chapsuk authored Sep 8, 2019
1 parent 728b23a commit b1d2ea4
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 1,149 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
language: go

go:
# - 1.9.x
- 1.10.x
# - tip
- 1.12.x
- 1.13.x

env:
global:
- GO111MODULE=on

services:
- redis-server

install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- go get github.com/golang/dep/cmd/dep

before_script:
- dep ensure
- go mod tidy

script:
- go test -v -covermode=count -coverprofile=coverage.out ./...
Expand Down
159 changes: 0 additions & 159 deletions Gopkg.lock

This file was deleted.

62 changes: 0 additions & 62 deletions Gopkg.toml

This file was deleted.

17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ wait until all runned workers finished when we need stop all jobs.
## Features

* Scheduling, use one from existing `worker.By*` schedule functions. Supporting cron schedule spec format by [robfig/cron](https://github.com/robfig/cron) parser.
* Control concurrent execution around multiple instances by `worker.With*` lock functions. Supporting redis locks by [go-redis/redis](github.com/go-redis/redis) and [bsm/redis-lock](https://github.com/bsm/redis-lock) pkgs.
* Control concurrent execution around multiple instances by `worker.WithLock`. See existing lockers
* Observe a job execution time duration with `worker.SetObserever`. Friendly for [prometheus/client_golang](https://github.com/prometheus/client_golang/) package.
* Graceful stop, wait until all running jobs was completed.

Expand All @@ -39,4 +39,17 @@ wg.Add(
wg.Run()
```

See more examples [here](/examples)
## Lockers

You can use redis locks for controll exclusive job execution:

```go
l := locker.NewRedis(radix.Client, "job_lock_name", locker.RedisLockTTL(time.Minute))

w := worker.
New(func(context.Context) {}).
WithLock(l)

// Job will be executed only if `job_lock_name` redis key not exists.
w.Run(context.Background())
```
8 changes: 2 additions & 6 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ or set custom schedule function
Exclusive jobs
Control concurrent execution around single or multiple instances by redis locks
Control concurrent execution around single or multiple instances by lockers
worker.
New(func(context.Context) {}).
WithRedisLock(&worker.RedisLockOptions{}).
WithLock(worker.Locker).
Run(context.Background())
or set custom locker
w.WithLock(worker.Locker)
Observe execution time
Collect job execution time metrics
Expand Down
72 changes: 0 additions & 72 deletions examples/custom/main.go

This file was deleted.

Loading

0 comments on commit b1d2ea4

Please sign in to comment.