Skip to content

Commit b050132

Browse files
committed
update readme
1 parent f307ee3 commit b050132

File tree

1 file changed

+54
-11
lines changed

1 file changed

+54
-11
lines changed

README.md

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ The job table contains only queued, scheduled and running tasks. The ended jobs
1515

1616
---
1717

18-
# 🛠️ Installation
19-
20-
## PyPI Installation (Recommended)
18+
## 🛠️ Installation
2119

2220
```bash
2321
pip install queuerPy
@@ -91,10 +89,10 @@ You can find a full example in the example folder.
9189
def new_queuer(name: str, max_concurrency: int, *options: OnError) -> Queuer
9290

9391
def new_queuer_with_db(
94-
name: str,
95-
max_concurrency: int,
96-
encryption_key: str,
97-
db_config: DatabaseConfiguration,
92+
name: str,
93+
max_concurrency: int,
94+
encryption_key: str,
95+
db_config: DatabaseConfiguration,
9896
*options: OnError
9997
) -> Queuer
10098
```
@@ -106,6 +104,7 @@ def new_queuer_with_db(
106104
- `options`: Optional `OnError` configurations to apply to the worker.
107105

108106
This function performs the following setup:
107+
109108
- Initializes a logger.
110109
- Sets up the database connection using the provided `db_config` or environment variables.
111110
- Creates `JobDBHandler`, `WorkerDBHandler` instances for database interactions.
@@ -124,6 +123,7 @@ def start(self) -> None
124123
```
125124

126125
Upon calling `start`:
126+
127127
- It performs a basic check to ensure internal listeners are initialized.
128128
- Database listeners are created to listen to job events (inserts, updates, deletes) via PostgreSQL NOTIFY/LISTEN.
129129
- 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
142142
def stop(self) -> None
143143
```
144144

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.
173+
174+
```python
175+
def stop_worker_gracefully(self, worker_rid: UUID) -> None
176+
```
177+
178+
- `worker_rid`: The `UUID` identifying the worker to stop gracefully.
179+
180+
When a worker is stopped gracefully:
181+
182+
- The worker status is set to `STOPPING` in the database
183+
- The heartbeat ticker detects the `STOPPING` status and sets `max_concurrency` to `0`
184+
- Currently running jobs are allowed to complete normally
185+
- No new jobs will be accepted by this worker
186+
- Once all running jobs have finished, the worker status is automatically set to `STOPPED` and the worker shuts down
187+
188+
This method is ideal for maintenance scenarios where you want to ensure all in-progress work completes before shutting down the worker.
146189

147190
---
148191

@@ -169,8 +212,8 @@ The `add_job` method adds a new job to the queue for execution. Jobs are units o
169212

170213
```python
171214
def add_job(
172-
self,
173-
task: Union[Callable, str],
215+
self,
216+
task: Union[Callable, str],
174217
*parameters: Any,
175218
**parameters_keyed: Any
176219
) -> Job
@@ -279,7 +322,7 @@ class RetryBackoff(str, Enum):
279322

280323
- `RETRY_BACKOFF_NONE`: No backoff. The retry_delay remains constant for all retries.
281324
- `RETRY_BACKOFF_LINEAR`: The retry delay increases linearly with each attempt (e.g., delay, 2*delay, 3*delay).
282-
- `RETRY_BACKOFF_EXPONENTIAL`: The retry delay increases exponentially with each attempt (e.g., delay, delay*2, delay*2*2).
325+
- `RETRY_BACKOFF_EXPONENTIAL`: The retry delay increases exponentially with each attempt (e.g., delay, delay*2, delay*2\*2).
283326

284327
---
285328

0 commit comments

Comments
 (0)