Skip to content

Commit af83c95

Browse files
authored
update readme (#20)
* add stop worker functionality * update readme with stop worker functionality
1 parent acccac8 commit af83c95

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,48 @@ The `Stop` method gracefully shuts down the Queuer instance, releasing resources
143143
func (q *Queuer) Stop() error
144144
```
145145

146-
The `Stop` method cancels all jobs, closes db listeners and returns an error if any step of the stopping process encounters an issue
146+
The `Stop` method cancels all jobs, closes db listeners and returns an error if any step of the stopping process encounters an issue. **Note:** This method can only be used to stop the current worker instance that the code is running in. To stop other workers, use `StopWorker` or `StopWorkerGracefully`.
147+
148+
---
149+
150+
## StopWorker
151+
152+
The `StopWorker` method immediately stops a worker by setting its status to `STOPPED`. This will cancel all running jobs on that worker.
153+
154+
```go
155+
func (q *Queuer) StopWorker(workerRID uuid.UUID) error
156+
```
157+
158+
- `workerRID`: The `uuid.UUID` identifying the worker to stop.
159+
160+
When a worker is stopped:
161+
- The worker status is immediately set to `STOPPED` in the database
162+
- The heartbeat ticker detects the `STOPPED` status and calls `Stop()` on that worker
163+
- All running jobs on that worker are cancelled immediately
164+
- The worker will no longer accept new jobs
165+
166+
This method is useful for immediately shutting down a worker, for example in emergency situations or when you need to take a worker offline quickly.
167+
168+
---
169+
170+
## StopWorkerGracefully
171+
172+
The `StopWorkerGracefully` method gracefully stops a worker by setting its status to `STOPPING`. This allows currently running jobs to complete before the worker shuts down.
173+
174+
```go
175+
func (q *Queuer) StopWorkerGracefully(workerRID uuid.UUID) error
176+
```
177+
178+
- `workerRID`: The `uuid.UUID` identifying the worker to stop gracefully.
179+
180+
When a worker is stopped gracefully:
181+
- The worker status is set to `STOPPING` in the database
182+
- The heartbeat ticker detects the `STOPPING` status and sets `maxConcurrency` to `0`
183+
- Currently running jobs are allowed to complete normally
184+
- No new jobs will be accepted by this worker
185+
- Once all running jobs have finished, the worker status is automatically set to `STOPPED` and the worker shuts down
186+
187+
This method is ideal for maintenance scenarios where you want to ensure all in-progress work completes before shutting down the worker.
147188

148189
---
149190

0 commit comments

Comments
 (0)