rrq 0.3.7__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rrq
3
- Version: 0.3.7
3
+ Version: 0.5.0
4
4
  Summary: RRQ is a Python library for creating reliable job queues using Redis and asyncio
5
5
  Project-URL: Homepage, https://github.com/getresq/rrq
6
6
  Project-URL: Bug Tracker, https://github.com/getresq/rrq/issues
@@ -20,7 +20,7 @@ Requires-Dist: pydantic>=2.11.4
20
20
  Requires-Dist: redis[hiredis]<6,>=4.2.0
21
21
  Requires-Dist: watchfiles>=0.19.0
22
22
  Provides-Extra: dev
23
- Requires-Dist: pytest-asyncio>=0.26.0; extra == 'dev'
23
+ Requires-Dist: pytest-asyncio>=1.0.0; extra == 'dev'
24
24
  Requires-Dist: pytest-cov>=6.0.0; extra == 'dev'
25
25
  Requires-Dist: pytest>=8.3.5; extra == 'dev'
26
26
  Description-Content-Type: text/markdown
@@ -40,6 +40,7 @@ RRQ is a Python library for creating reliable job queues using Redis and `asynci
40
40
  * **Graceful Shutdown**: Workers listen for SIGINT/SIGTERM and attempt to finish active jobs within a grace period before exiting. Interrupted jobs are re-queued.
41
41
  * **Worker Health Checks**: Workers periodically update a health key in Redis with a TTL, allowing monitoring systems to track active workers.
42
42
  * **Deferred Execution**: Jobs can be scheduled to run at a future time using `_defer_by` or `_defer_until`.
43
+ * **Cron Jobs**: Periodic jobs can be defined in `RRQSettings.cron_jobs` using a simple cron syntax.
43
44
 
44
45
  - Using deferral with a specific `_job_id` will effectively reschedule the job associated with that ID to the new time, overwriting its previous definition and score. It does not create multiple distinct scheduled jobs with the same ID.
45
46
 
@@ -138,6 +139,125 @@ if __name__ == "__main__":
138
139
 
139
140
  You can run multiple instances of `worker_script.py` for concurrent processing.
140
141
 
142
+ ## Cron Jobs
143
+
144
+ Add instances of `CronJob` to `RRQSettings.cron_jobs` to run periodic jobs. The
145
+ `schedule` string follows the typical five-field cron format `minute hour day-of-month month day-of-week`.
146
+ It supports the most common features from Unix cron:
147
+
148
+ - numeric values
149
+ - ranges (e.g. `8-11`)
150
+ - lists separated by commas (e.g. `mon,wed,fri`)
151
+ - step values using `/` (e.g. `*/15`)
152
+ - names for months and days (`jan-dec`, `sun-sat`)
153
+
154
+ Jobs are evaluated in the server's timezone and run with minute resolution.
155
+
156
+ ### Cron Schedule Examples
157
+
158
+ ```python
159
+ # Every minute
160
+ "* * * * *"
161
+
162
+ # Every hour at minute 30
163
+ "30 * * * *"
164
+
165
+ # Every day at 2:30 AM
166
+ "30 2 * * *"
167
+
168
+ # Every Monday at 9:00 AM
169
+ "0 9 * * mon"
170
+
171
+ # Every 15 minutes
172
+ "*/15 * * * *"
173
+
174
+ # Every weekday at 6:00 PM
175
+ "0 18 * * mon-fri"
176
+
177
+ # First day of every month at midnight
178
+ "0 0 1 * *"
179
+
180
+ # Every 2 hours during business hours on weekdays
181
+ "0 9-17/2 * * mon-fri"
182
+ ```
183
+
184
+ ### Defining Cron Jobs
185
+
186
+ ```python
187
+ from rrq.settings import RRQSettings
188
+ from rrq.cron import CronJob
189
+
190
+ # Define your cron jobs
191
+ cron_jobs = [
192
+ # Daily cleanup at 2 AM
193
+ CronJob(
194
+ function_name="daily_cleanup",
195
+ schedule="0 2 * * *",
196
+ args=["temp_files"],
197
+ kwargs={"max_age_days": 7}
198
+ ),
199
+
200
+ # Weekly report every Monday at 9 AM
201
+ CronJob(
202
+ function_name="generate_weekly_report",
203
+ schedule="0 9 * * mon",
204
+ unique=True # Prevent duplicate reports if worker restarts
205
+ ),
206
+
207
+ # Health check every 15 minutes on a specific queue
208
+ CronJob(
209
+ function_name="system_health_check",
210
+ schedule="*/15 * * * *",
211
+ queue_name="monitoring"
212
+ ),
213
+
214
+ # Backup database every night at 1 AM
215
+ CronJob(
216
+ function_name="backup_database",
217
+ schedule="0 1 * * *",
218
+ kwargs={"backup_type": "incremental"}
219
+ ),
220
+ ]
221
+
222
+ # Add to your settings
223
+ rrq_settings = RRQSettings(
224
+ redis_dsn="redis://localhost:6379/0",
225
+ cron_jobs=cron_jobs
226
+ )
227
+ ```
228
+
229
+ ### Cron Job Handlers
230
+
231
+ Your cron job handlers are regular async functions, just like other job handlers:
232
+
233
+ ```python
234
+ async def daily_cleanup(ctx, file_type: str, max_age_days: int = 7):
235
+ """Clean up old files."""
236
+ job_id = ctx['job_id']
237
+ print(f"Job {job_id}: Cleaning up {file_type} files older than {max_age_days} days")
238
+ # Your cleanup logic here
239
+ return {"cleaned_files": 42, "status": "completed"}
240
+
241
+ async def generate_weekly_report(ctx):
242
+ """Generate and send weekly report."""
243
+ job_id = ctx['job_id']
244
+ print(f"Job {job_id}: Generating weekly report")
245
+ # Your report generation logic here
246
+ return {"report_id": "weekly_2024_01", "status": "sent"}
247
+
248
+ # Register your handlers
249
+ from rrq.registry import JobRegistry
250
+
251
+ job_registry = JobRegistry()
252
+ job_registry.register("daily_cleanup", daily_cleanup)
253
+ job_registry.register("generate_weekly_report", generate_weekly_report)
254
+
255
+ # Add the registry to your settings
256
+ rrq_settings.job_registry = job_registry
257
+ ```
258
+
259
+ **Note:** Cron jobs are automatically enqueued by the worker when they become due. The worker checks for due cron jobs every 30 seconds and enqueues them as regular jobs to be processed.
260
+
141
261
  ## Command Line Interface
142
262
 
143
263
  RRQ provides a command-line interface (CLI) for managing workers and performing health checks:
@@ -145,7 +265,8 @@ RRQ provides a command-line interface (CLI) for managing workers and performing
145
265
  - **`rrq worker run`** - Run an RRQ worker process.
146
266
  - `--settings` (optional): Specify the Python path to your settings object (e.g., `myapp.worker_config.rrq_settings`). If not provided, it will use the `RRQ_SETTINGS` environment variable or default to a basic `RRQSettings` object.
147
267
  - `--queue` (optional, multiple): Specify queue(s) to poll. Defaults to the `default_queue_name` in settings.
148
- - `--burst` (flag): Run the worker in burst mode to process one job or batch and then exit.
268
+ - `--burst` (flag): Run the worker in burst mode to process one job or batch and then exit. Cannot be used with `--num-workers > 1`.
269
+ - `--num-workers` (optional, integer): Number of parallel worker processes to start. Defaults to the number of CPU cores available on the machine. Cannot be used with `--burst` mode.
149
270
  - **`rrq worker watch`** - Run an RRQ worker with auto-restart on file changes.
150
271
  - `--path` (optional): Directory path to watch for changes. Defaults to the current directory.
151
272
  - `--settings` (optional): Same as above.
@@ -178,7 +299,4 @@ RRQ can be configured in several ways, with the following precedence:
178
299
  * **`JobRegistry` (`registry.py`)**: A simple registry to map string function names (used when enqueuing) to the actual asynchronous handler functions the worker should execute.
179
300
  * **`JobStore` (`store.py`)**: An abstraction layer handling all direct interactions with Redis. It manages job definitions (Hashes), queues (Sorted Sets), processing locks (Strings with TTL), unique job locks, and worker health checks.
180
301
  * **`Job` (`job.py`)**: A Pydantic model representing a job, containing its ID, handler name, arguments, status, retry counts, timestamps, results, etc.
181
- * **`JobStatus` (`job.py`)**: An Enum defining the possible states of a job (`PENDING`, `ACTIVE`, `COMPLETED`, `FAILED`, `RETRYING`).
182
- * **`RRQSettings` (`settings.py`)**: A Pydantic `BaseSettings` model for configuring RRQ behavior (Redis DSN, queue names, timeouts, retry policies, concurrency, etc.). Loadable from environment variables (prefix `RRQ_`).
183
- * **`constants.py`**: Defines shared constants like Redis key prefixes and default configuration values.
184
- * **`exc.py`**: Defines custom exceptions, notably `RetryJob` which handlers can raise to explicitly request a retry, potentially with a custom delay.
302
+ * **`JobStatus` (`job.py`)**: An Enum defining the possible states of a job (`PENDING`, `ACTIVE`, `COMPLETED`, `FAILED`, `
@@ -0,0 +1,16 @@
1
+ rrq/__init__.py,sha256=3WYv9UkvnCbjKXrvmqiLm7yuVVQiLclbVCOXq5wb6ZM,290
2
+ rrq/cli.py,sha256=7wLO0gRl8Qe1Tf6dyELJnVfJc6rr5pw6m6Mj7qMl3bk,27550
3
+ rrq/client.py,sha256=5_bmZ05LKIfY9WFSKU-nYawEupsnrnHT2HewXfC2Ahg,7831
4
+ rrq/constants.py,sha256=F_uZgBI3h00MctnEjBjiCGMrg5jUaz5Bz9I1vkyqNrs,1654
5
+ rrq/cron.py,sha256=etDwnOXr5Ys1Vt08oYQsMjtLbPsjMWMvbund4bWOlCA,5237
6
+ rrq/exc.py,sha256=NJq3C7pUfcd47AB8kghIN8vdY0l90UrsHQEg4McBHP8,1281
7
+ rrq/job.py,sha256=eUbl33QDqDMXPKpo-0dl0Mp29LWWmtbBgRw0sclcwJ4,4011
8
+ rrq/registry.py,sha256=E9W_zx3QiKTBwMOGearaNpDKBDB87JIn0RlMQ3sAcP0,2925
9
+ rrq/settings.py,sha256=AxzSe_rw7-yduKST2c9mPunQWqPE2537XcC_XlMoHWM,4535
10
+ rrq/store.py,sha256=TrtVojnT7wJNV1jaXsjHXQa3IDeQJ4-0PKDCEjZuDi0,29537
11
+ rrq/worker.py,sha256=1bbZkUCSHwFzpsxcsc84RU_7h8dCnFItJCZ4SG4zASc,44940
12
+ rrq-0.5.0.dist-info/METADATA,sha256=vud54ZneWCUMJ0pjg_FmUHaBo1oxqOBbw2yC63gMKy0,13140
13
+ rrq-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ rrq-0.5.0.dist-info/entry_points.txt,sha256=f8eFjk2ygDSyu9USwXGj5IM8xeyQqZgDa1rSrCj4Mis,36
15
+ rrq-0.5.0.dist-info/licenses/LICENSE,sha256=XDvu5hKdS2-_ByiSj3tiu_3zSsrXXoJsgbILGoMpKCw,554
16
+ rrq-0.5.0.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- rrq/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- rrq/cli.py,sha256=_LbaAH_w2a0VNRR0EctuE4afl-wccvMY2w2VbehFDEQ,16980
3
- rrq/client.py,sha256=5_bmZ05LKIfY9WFSKU-nYawEupsnrnHT2HewXfC2Ahg,7831
4
- rrq/constants.py,sha256=F_uZgBI3h00MctnEjBjiCGMrg5jUaz5Bz9I1vkyqNrs,1654
5
- rrq/exc.py,sha256=NJq3C7pUfcd47AB8kghIN8vdY0l90UrsHQEg4McBHP8,1281
6
- rrq/job.py,sha256=eUbl33QDqDMXPKpo-0dl0Mp29LWWmtbBgRw0sclcwJ4,4011
7
- rrq/registry.py,sha256=E9W_zx3QiKTBwMOGearaNpDKBDB87JIn0RlMQ3sAcP0,2925
8
- rrq/settings.py,sha256=BPKP4XjG7z475gqRgHZt4-IvvOs8uZefq4fPfD2Bepk,4350
9
- rrq/store.py,sha256=teO0Af8hzBiu7-dFn6_2lz5X90LAZXmtg0VDZuQoAwk,24972
10
- rrq/worker.py,sha256=y0UTziZVh4QbOPv24b8cqbm_xDBM0HtJLwPNYsJPWnE,40706
11
- rrq-0.3.7.dist-info/METADATA,sha256=fqMod1pTxebf7d4fCh5vRK0o9gkD4OAYg-02TNHJfN4,10193
12
- rrq-0.3.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
- rrq-0.3.7.dist-info/entry_points.txt,sha256=f8eFjk2ygDSyu9USwXGj5IM8xeyQqZgDa1rSrCj4Mis,36
14
- rrq-0.3.7.dist-info/licenses/LICENSE,sha256=XDvu5hKdS2-_ByiSj3tiu_3zSsrXXoJsgbILGoMpKCw,554
15
- rrq-0.3.7.dist-info/RECORD,,
File without changes