Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to check if pool has been started #15

Merged
merged 1 commit into from
Mar 12, 2021
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
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gocraft/work lets you enqueue and processes background jobs in Go. Jobs are dura
* Periodically enqueue jobs on a cron-like schedule.
* Pause / unpause jobs and control concurrency within and across processes

---

## Fork - Important Changes

#### Usage
Expand Down Expand Up @@ -42,13 +44,19 @@ in-progress queue was lost.
#### Expose lock count & max concurrency for each job (#2)

Added to the queue info accessible from
[`work.Client.Queues()`](https://pkg.go.dev/github.com/gojek/work#Client.Queues). Useful for alerting when lock count is
consistently equal to the max concurrency possibly indicating that stale lock count is resulting in jobs not being
picked up.
[`work.Client.Queues()`](/client.go#L205-L212). Useful for alerting when lock count is consistently equal to the max
concurrency possibly indicating that stale lock count is resulting in jobs not being picked up.

For the cleanup to be thorough, [`work.(*WorkerPool).Stop`](https://pkg.go.dev/github.com/gojek/work#WorkerPool.Stop)
would need to be called on each worker pool instance.

#### Worker pool started check

Expose [`work.(*WorkerPool).Started`](/worker_pool.go#L195-L198) which can be used to check if the worker pool has been
started and is running.

---

## Enqueue new jobs

To enqueue jobs, you need to make an Enqueuer with a redis namespace and a redigo pool. Each enqueued job has a name and can take optional arguments. Arguments are k/v pairs (serialized as JSON internally).
Expand Down
5 changes: 5 additions & 0 deletions worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ func (wp *WorkerPool) PeriodicallyEnqueue(spec string, jobName string) *WorkerPo
return wp
}

// Started returns true if the worker pool has been started.
func (wp *WorkerPool) Started() bool {
return wp.started
}

// Start starts the workers and associated processes.
func (wp *WorkerPool) Start() {
if wp.started {
Expand Down
12 changes: 12 additions & 0 deletions worker_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ func TestWorkerPoolStartStop(t *testing.T) {
wp.Stop()
}

func TestWorkerPoolStarted(t *testing.T) {
pool := newTestPool(t)
ns := "work"
wp := NewWorkerPool(TestContext{}, 10, ns, pool)

assert.False(t, wp.Started())
wp.Start()
assert.True(t, wp.Started())
wp.Stop()
assert.False(t, wp.Started())
}

func TestWorkerPoolValidations(t *testing.T) {
pool := newTestPool(t)
ns := "work"
Expand Down