You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`options`: Optional `OnError` configurations to apply to the worker.
107
105
108
106
This function performs the following setup:
107
+
109
108
- Initializes a logger.
110
109
- Sets up the database connection using the provided `db_config`or environment variables.
111
110
- Creates `JobDBHandler`, `WorkerDBHandler` instances for database interactions.
@@ -124,6 +123,7 @@ def start(self) -> None
124
123
```
125
124
126
125
Upon calling `start`:
126
+
127
127
- It performs a basic check to ensure internal listeners are initialized.
128
128
- Database listeners are created to listen to job events (inserts, updates, deletes) via PostgreSQL NOTIFY/LISTEN.
129
129
- It starts a poller to periodically poll the database for new jobs to process.
@@ -142,7 +142,50 @@ The `stop` method gracefully shuts down the Queuer instance, releasing resources
142
142
def stop(self) ->None
143
143
```
144
144
145
-
The `stop` method cancels all jobs, closes database listeners, and cleans up resources.
145
+
The `stop` method cancels all jobs, closes database listeners, and cleans up resources. **Note:** This method can only be used to stop the current worker instance that the code is running in. To stop other workers, use `stop_worker`or`stop_worker_gracefully`.
146
+
147
+
---
148
+
149
+
## stop_worker
150
+
151
+
The `stop_worker` method immediately stops a worker by setting its status to `STOPPED`. This will cancel all running jobs on that worker.
152
+
153
+
```python
154
+
def stop_worker(self, worker_rid: UUID) ->None
155
+
```
156
+
157
+
-`worker_rid`: The `UUID` identifying the worker to stop.
158
+
159
+
When a worker is stopped:
160
+
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
+
## stop_worker_gracefully
171
+
172
+
The `stop_worker_gracefully` method gracefully stops a worker by setting its status to `STOPPING`. This allows currently running jobs to complete before the worker shuts down.
0 commit comments