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
docs: update README and tests for time index cleanup logic
- Expanded README to include details on interval tasks and the new `{prefix}:time_index` sorted set for tracking schedules.
- Updated cleanup logic in `ListRedisScheduleSource` to remove stale entries older than 5 minutes instead of 1 hour.
- Modified tests to reflect the new 5-minute threshold for cleanup, ensuring accurate verification of the time index behavior.
Copy file name to clipboardExpand all lines: README.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,9 +154,26 @@ This is very ineficent and should not be used for high-volume schedules. Because
154
154
This source holds values in lists.
155
155
156
156
* For cron tasks it uses key `{prefix}:cron`.
157
+
* For interval tasks it uses key `{prefix}:interval`.
157
158
* For timed schedules it uses key `{prefix}:time:{time}` where `{time}`is actually time where schedules should run.
159
+
* A sortedset at `{prefix}:time_index` tracks all time keys with their unix timestamps as scores, so that past time schedules can be discovered via `ZRANGEBYSCORE` instead of scanning all Redis keys. Stale entries (older than 5 minutes with empty time key lists) are cleaned up automatically.
158
160
159
-
The main advantage of this approach is that we only fetch tasks we need to run at a given time and do not perform any excesive calls to redis.
161
+
The main advantage of this approach is that we only fetch tasks we need to run at a given time and do not perform any excessive calls to redis.
162
+
163
+
#### `populate_time_index`
164
+
165
+
If you are upgrading from an older version that did not maintain the `{prefix}:time_index`sortedset, existing time keys will not be present in the index. Set `populate_time_index=True` once on startup to backfill the index via a one-time `SCAN`, then set it back to `False`for subsequent runs:
166
+
167
+
```python
168
+
# First run after upgrading — backfills the time index
169
+
source = ListRedisScheduleSource(
170
+
"redis://localhost/1",
171
+
populate_time_index=True,
172
+
)
173
+
174
+
# All subsequent runs — no SCAN, uses the time index
0 commit comments