jobstreaming 0.0.1__tar.gz → 0.0.2__tar.gz
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.
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/PKG-INFO +80 -10
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/README.md +78 -9
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/__init__.py +28 -1
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/api.py +25 -5
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/bayt/__init__.py +1 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/bdjobs/__init__.py +1 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/checkpoint.py +8 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/events.py +20 -3
- jobstreaming-0.0.2/jobstreaming/exception.py +211 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/glassdoor/__init__.py +17 -4
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/google/__init__.py +1 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/indeed/__init__.py +12 -3
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/linkedin/__init__.py +6 -6
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/model.py +1 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/naukri/__init__.py +1 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/registry.py +28 -1
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/runtime.py +208 -34
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/ziprecruiter/__init__.py +7 -6
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/pyproject.toml +3 -2
- jobstreaming-0.0.1/jobstreaming/exception.py +0 -46
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/LICENSE +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/bdjobs/constant.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/bdjobs/util.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/glassdoor/constant.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/glassdoor/util.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/google/constant.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/google/util.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/indeed/constant.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/indeed/util.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/linkedin/constant.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/linkedin/util.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/naukri/constant.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/naukri/util.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/result.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/util.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/ziprecruiter/constant.py +0 -0
- {jobstreaming-0.0.1 → jobstreaming-0.0.2}/jobstreaming/ziprecruiter/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jobstreaming
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Concurrent, resumable job search streams with a DataFrame batch API
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
17
|
Requires-Dist: beautifulsoup4 (>=4.12.2,<5.0.0)
|
|
17
18
|
Requires-Dist: markdownify (>=1.1.0,<2.0.0)
|
|
18
19
|
Requires-Dist: pandas (>=2.1.0,<3.0.0)
|
|
@@ -67,7 +68,7 @@ flowchart LR
|
|
|
67
68
|
|
|
68
69
|
## Installation
|
|
69
70
|
|
|
70
|
-
Python 3.10
|
|
71
|
+
Python 3.10 through Python 3.14 are tested.
|
|
71
72
|
|
|
72
73
|
Install the published package from PyPI:
|
|
73
74
|
|
|
@@ -91,6 +92,7 @@ with stream_search(
|
|
|
91
92
|
results_wanted=20, # per site
|
|
92
93
|
checkpoint_path=".jobstreaming/search.json",
|
|
93
94
|
resume=True,
|
|
95
|
+
ack_mode="explicit",
|
|
94
96
|
) as stream:
|
|
95
97
|
for event in stream:
|
|
96
98
|
if isinstance(event, JobEvent):
|
|
@@ -98,13 +100,14 @@ with stream_search(
|
|
|
98
100
|
|
|
99
101
|
# Persist the job first when durability matters, then explicitly ack it.
|
|
100
102
|
save_to_database(event.job)
|
|
101
|
-
stream.ack(event)
|
|
102
103
|
|
|
103
104
|
elif isinstance(event, ErrorEvent):
|
|
104
105
|
print(f"{event.site.value} failed: {event.message}")
|
|
105
106
|
|
|
106
107
|
elif isinstance(event, SearchCompleteEvent):
|
|
107
108
|
print("all sites completed:", event.completed)
|
|
109
|
+
|
|
110
|
+
stream.ack(event)
|
|
108
111
|
```
|
|
109
112
|
|
|
110
113
|
Each site runs in its own worker. Arrival order is intentionally unspecified: faster
|
|
@@ -131,7 +134,11 @@ checkpoint acknowledgements.
|
|
|
131
134
|
|
|
132
135
|
Checkpointing is opt-in. Pass either `checkpoint_path` or a custom `CheckpointStore`.
|
|
133
136
|
|
|
134
|
-
-
|
|
137
|
+
- The default `ack_mode="implicit"` preserves the convenient behavior where requesting
|
|
138
|
+
the next event acknowledges the previous event.
|
|
139
|
+
- Use `ack_mode="explicit"` for durable consumers. In this mode, requesting another
|
|
140
|
+
event before `stream.ack(event)` raises `UnacknowledgedEventError` and does not advance
|
|
141
|
+
the checkpoint.
|
|
135
142
|
- Call `stream.ack(event)` after a durable write when you need the checkpoint advanced
|
|
136
143
|
immediately.
|
|
137
144
|
- Leaving the context manager early does not acknowledge the last delivered event;
|
|
@@ -142,14 +149,22 @@ Checkpointing is opt-in. Pass either `checkpoint_path` or a custom `CheckpointSt
|
|
|
142
149
|
- Acknowledged jobs are deduplicated with stable, process-independent keys.
|
|
143
150
|
- Page and cursor state advances only after the corresponding progress event is
|
|
144
151
|
acknowledged.
|
|
145
|
-
-
|
|
146
|
-
Configure `max_retries` and `retry_backoff` on `stream_search` or
|
|
152
|
+
- Only failures classified as `transient_network` or `rate_limited` are retried by
|
|
153
|
+
default. Configure `max_retries` and `retry_backoff` on `stream_search` or
|
|
154
|
+
`scrape_jobs`.
|
|
147
155
|
- The checkpoint is written through an `fsync` plus atomic file replacement.
|
|
156
|
+
- Checkpoints carry an overall schema version, a monotonically increasing revision, and
|
|
157
|
+
a cursor-state schema version for every adapter. An incompatible library or adapter
|
|
158
|
+
upgrade raises `CheckpointCompatibilityError` before any board worker starts.
|
|
148
159
|
- A checkpoint is bound to the complete request fingerprint. Changing the query,
|
|
149
160
|
filters, sites, or result count raises `CheckpointMismatchError`; use a new path or
|
|
150
161
|
`resume=False` for a new search.
|
|
151
162
|
- Board-owned cursors can expire. If a board rejects an old cursor, the stream emits an
|
|
152
|
-
`ErrorEvent
|
|
163
|
+
`ErrorEvent` with `code="cursor_expired"` and `reset_checkpoint=True`; restart that
|
|
164
|
+
site from a fresh checkpoint.
|
|
165
|
+
- Custom stores can provide compare-and-swap ownership using `checkpoint.revision`.
|
|
166
|
+
Raise `CheckpointConflictError` for a stale save; the conflict is surfaced to the
|
|
167
|
+
caller immediately and the stream stops without advancing its local checkpoint.
|
|
153
168
|
|
|
154
169
|
If a process crashes while handling a job, replay is expected. Make downstream writes
|
|
155
170
|
idempotent using `event.job_key` or the job's stable `id`.
|
|
@@ -194,6 +209,46 @@ store before acknowledging it.
|
|
|
194
209
|
| `SiteCompleteEvent` | One site exhausted its work or reached its result limit. |
|
|
195
210
|
| `SearchCompleteEvent` | Every worker stopped. `completed=False` means at least one site failed. |
|
|
196
211
|
|
|
212
|
+
`ErrorEvent.code` is a stable `ErrorCode` value. `retryable` tells an operator whether
|
|
213
|
+
the same board operation can be retried, while `reset_checkpoint` tells them whether
|
|
214
|
+
the board cursor should be discarded first.
|
|
215
|
+
|
|
216
|
+
| Error code | Retry | Reset board checkpoint |
|
|
217
|
+
|---|---:|---:|
|
|
218
|
+
| `transient_network` | yes | no |
|
|
219
|
+
| `rate_limited` | yes | no |
|
|
220
|
+
| `invalid_request` | no | no |
|
|
221
|
+
| `cursor_expired` | no | yes |
|
|
222
|
+
| `authentication_configuration` | no | no |
|
|
223
|
+
| `cancelled` | no | no |
|
|
224
|
+
| `adapter_failure` | no | no |
|
|
225
|
+
|
|
226
|
+
## Cancellation
|
|
227
|
+
|
|
228
|
+
Supply a `threading.Event`, a callback, or both. Queue waits, retry backoff, and blocked
|
|
229
|
+
adapter/network operations are observed through the same cancellation boundary.
|
|
230
|
+
`close()` also wakes a consumer blocked in `next()`.
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
from threading import Event
|
|
234
|
+
|
|
235
|
+
from jobstreaming import StreamCancelledError, stream_search
|
|
236
|
+
|
|
237
|
+
cancel = Event()
|
|
238
|
+
|
|
239
|
+
try:
|
|
240
|
+
with stream_search(
|
|
241
|
+
site_name=["indeed", "linkedin"],
|
|
242
|
+
search_term="platform engineer",
|
|
243
|
+
cancel_event=cancel,
|
|
244
|
+
# cancel_callback=lambda: shutdown_requested(), # optional alternative
|
|
245
|
+
) as stream:
|
|
246
|
+
for event in stream:
|
|
247
|
+
process(event)
|
|
248
|
+
except StreamCancelledError:
|
|
249
|
+
pass
|
|
250
|
+
```
|
|
251
|
+
|
|
197
252
|
## Supported sites and important limits
|
|
198
253
|
|
|
199
254
|
| Site | Restart boundary | Notes |
|
|
@@ -239,9 +294,22 @@ job titles/URLs, and unsupported enum values are rejected at the boundary.
|
|
|
239
294
|
## Custom adapters
|
|
240
295
|
|
|
241
296
|
```python
|
|
242
|
-
from jobstreaming import
|
|
297
|
+
from jobstreaming import (
|
|
298
|
+
AdapterCapabilities,
|
|
299
|
+
AdapterRegistry,
|
|
300
|
+
JobResponse,
|
|
301
|
+
Scraper,
|
|
302
|
+
Site,
|
|
303
|
+
stream_search,
|
|
304
|
+
)
|
|
243
305
|
|
|
244
306
|
class InternalJobs(Scraper):
|
|
307
|
+
capabilities = AdapterCapabilities(
|
|
308
|
+
supports_resume=True,
|
|
309
|
+
resume_granularity="cursor",
|
|
310
|
+
cursor_schema_version=1,
|
|
311
|
+
)
|
|
312
|
+
|
|
245
313
|
def __init__(self, **kwargs):
|
|
246
314
|
super().__init__(Site.INDEED) # this example replaces the Indeed adapter
|
|
247
315
|
|
|
@@ -262,8 +330,10 @@ with stream_search(
|
|
|
262
330
|
...
|
|
263
331
|
```
|
|
264
332
|
|
|
265
|
-
|
|
266
|
-
|
|
333
|
+
Increment `cursor_schema_version` whenever a deployed adapter can no longer interpret
|
|
334
|
+
cursor state written by its previous implementation. Legacy adapters that only return
|
|
335
|
+
`JobResponse` are still accepted, but their results cannot be streamed until that
|
|
336
|
+
adapter returns.
|
|
267
337
|
|
|
268
338
|
The registry can replace any built-in adapter. Adding an entirely new site also
|
|
269
339
|
requires adding that board to the `Site` enum so it participates in validation,
|
|
@@ -44,7 +44,7 @@ flowchart LR
|
|
|
44
44
|
|
|
45
45
|
## Installation
|
|
46
46
|
|
|
47
|
-
Python 3.10
|
|
47
|
+
Python 3.10 through Python 3.14 are tested.
|
|
48
48
|
|
|
49
49
|
Install the published package from PyPI:
|
|
50
50
|
|
|
@@ -68,6 +68,7 @@ with stream_search(
|
|
|
68
68
|
results_wanted=20, # per site
|
|
69
69
|
checkpoint_path=".jobstreaming/search.json",
|
|
70
70
|
resume=True,
|
|
71
|
+
ack_mode="explicit",
|
|
71
72
|
) as stream:
|
|
72
73
|
for event in stream:
|
|
73
74
|
if isinstance(event, JobEvent):
|
|
@@ -75,13 +76,14 @@ with stream_search(
|
|
|
75
76
|
|
|
76
77
|
# Persist the job first when durability matters, then explicitly ack it.
|
|
77
78
|
save_to_database(event.job)
|
|
78
|
-
stream.ack(event)
|
|
79
79
|
|
|
80
80
|
elif isinstance(event, ErrorEvent):
|
|
81
81
|
print(f"{event.site.value} failed: {event.message}")
|
|
82
82
|
|
|
83
83
|
elif isinstance(event, SearchCompleteEvent):
|
|
84
84
|
print("all sites completed:", event.completed)
|
|
85
|
+
|
|
86
|
+
stream.ack(event)
|
|
85
87
|
```
|
|
86
88
|
|
|
87
89
|
Each site runs in its own worker. Arrival order is intentionally unspecified: faster
|
|
@@ -108,7 +110,11 @@ checkpoint acknowledgements.
|
|
|
108
110
|
|
|
109
111
|
Checkpointing is opt-in. Pass either `checkpoint_path` or a custom `CheckpointStore`.
|
|
110
112
|
|
|
111
|
-
-
|
|
113
|
+
- The default `ack_mode="implicit"` preserves the convenient behavior where requesting
|
|
114
|
+
the next event acknowledges the previous event.
|
|
115
|
+
- Use `ack_mode="explicit"` for durable consumers. In this mode, requesting another
|
|
116
|
+
event before `stream.ack(event)` raises `UnacknowledgedEventError` and does not advance
|
|
117
|
+
the checkpoint.
|
|
112
118
|
- Call `stream.ack(event)` after a durable write when you need the checkpoint advanced
|
|
113
119
|
immediately.
|
|
114
120
|
- Leaving the context manager early does not acknowledge the last delivered event;
|
|
@@ -119,14 +125,22 @@ Checkpointing is opt-in. Pass either `checkpoint_path` or a custom `CheckpointSt
|
|
|
119
125
|
- Acknowledged jobs are deduplicated with stable, process-independent keys.
|
|
120
126
|
- Page and cursor state advances only after the corresponding progress event is
|
|
121
127
|
acknowledged.
|
|
122
|
-
-
|
|
123
|
-
Configure `max_retries` and `retry_backoff` on `stream_search` or
|
|
128
|
+
- Only failures classified as `transient_network` or `rate_limited` are retried by
|
|
129
|
+
default. Configure `max_retries` and `retry_backoff` on `stream_search` or
|
|
130
|
+
`scrape_jobs`.
|
|
124
131
|
- The checkpoint is written through an `fsync` plus atomic file replacement.
|
|
132
|
+
- Checkpoints carry an overall schema version, a monotonically increasing revision, and
|
|
133
|
+
a cursor-state schema version for every adapter. An incompatible library or adapter
|
|
134
|
+
upgrade raises `CheckpointCompatibilityError` before any board worker starts.
|
|
125
135
|
- A checkpoint is bound to the complete request fingerprint. Changing the query,
|
|
126
136
|
filters, sites, or result count raises `CheckpointMismatchError`; use a new path or
|
|
127
137
|
`resume=False` for a new search.
|
|
128
138
|
- Board-owned cursors can expire. If a board rejects an old cursor, the stream emits an
|
|
129
|
-
`ErrorEvent
|
|
139
|
+
`ErrorEvent` with `code="cursor_expired"` and `reset_checkpoint=True`; restart that
|
|
140
|
+
site from a fresh checkpoint.
|
|
141
|
+
- Custom stores can provide compare-and-swap ownership using `checkpoint.revision`.
|
|
142
|
+
Raise `CheckpointConflictError` for a stale save; the conflict is surfaced to the
|
|
143
|
+
caller immediately and the stream stops without advancing its local checkpoint.
|
|
130
144
|
|
|
131
145
|
If a process crashes while handling a job, replay is expected. Make downstream writes
|
|
132
146
|
idempotent using `event.job_key` or the job's stable `id`.
|
|
@@ -171,6 +185,46 @@ store before acknowledging it.
|
|
|
171
185
|
| `SiteCompleteEvent` | One site exhausted its work or reached its result limit. |
|
|
172
186
|
| `SearchCompleteEvent` | Every worker stopped. `completed=False` means at least one site failed. |
|
|
173
187
|
|
|
188
|
+
`ErrorEvent.code` is a stable `ErrorCode` value. `retryable` tells an operator whether
|
|
189
|
+
the same board operation can be retried, while `reset_checkpoint` tells them whether
|
|
190
|
+
the board cursor should be discarded first.
|
|
191
|
+
|
|
192
|
+
| Error code | Retry | Reset board checkpoint |
|
|
193
|
+
|---|---:|---:|
|
|
194
|
+
| `transient_network` | yes | no |
|
|
195
|
+
| `rate_limited` | yes | no |
|
|
196
|
+
| `invalid_request` | no | no |
|
|
197
|
+
| `cursor_expired` | no | yes |
|
|
198
|
+
| `authentication_configuration` | no | no |
|
|
199
|
+
| `cancelled` | no | no |
|
|
200
|
+
| `adapter_failure` | no | no |
|
|
201
|
+
|
|
202
|
+
## Cancellation
|
|
203
|
+
|
|
204
|
+
Supply a `threading.Event`, a callback, or both. Queue waits, retry backoff, and blocked
|
|
205
|
+
adapter/network operations are observed through the same cancellation boundary.
|
|
206
|
+
`close()` also wakes a consumer blocked in `next()`.
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from threading import Event
|
|
210
|
+
|
|
211
|
+
from jobstreaming import StreamCancelledError, stream_search
|
|
212
|
+
|
|
213
|
+
cancel = Event()
|
|
214
|
+
|
|
215
|
+
try:
|
|
216
|
+
with stream_search(
|
|
217
|
+
site_name=["indeed", "linkedin"],
|
|
218
|
+
search_term="platform engineer",
|
|
219
|
+
cancel_event=cancel,
|
|
220
|
+
# cancel_callback=lambda: shutdown_requested(), # optional alternative
|
|
221
|
+
) as stream:
|
|
222
|
+
for event in stream:
|
|
223
|
+
process(event)
|
|
224
|
+
except StreamCancelledError:
|
|
225
|
+
pass
|
|
226
|
+
```
|
|
227
|
+
|
|
174
228
|
## Supported sites and important limits
|
|
175
229
|
|
|
176
230
|
| Site | Restart boundary | Notes |
|
|
@@ -216,9 +270,22 @@ job titles/URLs, and unsupported enum values are rejected at the boundary.
|
|
|
216
270
|
## Custom adapters
|
|
217
271
|
|
|
218
272
|
```python
|
|
219
|
-
from jobstreaming import
|
|
273
|
+
from jobstreaming import (
|
|
274
|
+
AdapterCapabilities,
|
|
275
|
+
AdapterRegistry,
|
|
276
|
+
JobResponse,
|
|
277
|
+
Scraper,
|
|
278
|
+
Site,
|
|
279
|
+
stream_search,
|
|
280
|
+
)
|
|
220
281
|
|
|
221
282
|
class InternalJobs(Scraper):
|
|
283
|
+
capabilities = AdapterCapabilities(
|
|
284
|
+
supports_resume=True,
|
|
285
|
+
resume_granularity="cursor",
|
|
286
|
+
cursor_schema_version=1,
|
|
287
|
+
)
|
|
288
|
+
|
|
222
289
|
def __init__(self, **kwargs):
|
|
223
290
|
super().__init__(Site.INDEED) # this example replaces the Indeed adapter
|
|
224
291
|
|
|
@@ -239,8 +306,10 @@ with stream_search(
|
|
|
239
306
|
...
|
|
240
307
|
```
|
|
241
308
|
|
|
242
|
-
|
|
243
|
-
|
|
309
|
+
Increment `cursor_schema_version` whenever a deployed adapter can no longer interpret
|
|
310
|
+
cursor state written by its previous implementation. Legacy adapters that only return
|
|
311
|
+
`JobResponse` are still accepted, but their results cannot be streamed until that
|
|
312
|
+
adapter returns.
|
|
244
313
|
|
|
245
314
|
The registry can replace any built-in adapter. Adding an entirely new site also
|
|
246
315
|
requires adding that board to the `Site` enum so it participates in validation,
|
|
@@ -5,8 +5,11 @@ from jobstreaming.api import (
|
|
|
5
5
|
stream_search,
|
|
6
6
|
)
|
|
7
7
|
from jobstreaming.checkpoint import (
|
|
8
|
+
CheckpointCompatibilityError,
|
|
9
|
+
CheckpointConflictError,
|
|
8
10
|
CheckpointError,
|
|
9
11
|
CheckpointMismatchError,
|
|
12
|
+
CheckpointStore,
|
|
10
13
|
JsonFileCheckpointStore,
|
|
11
14
|
MemoryCheckpointStore,
|
|
12
15
|
)
|
|
@@ -21,6 +24,17 @@ from jobstreaming.events import (
|
|
|
21
24
|
SiteCompleteEvent,
|
|
22
25
|
WarningEvent,
|
|
23
26
|
)
|
|
27
|
+
from jobstreaming.exception import (
|
|
28
|
+
AuthenticationConfigurationError,
|
|
29
|
+
CursorExpiredError,
|
|
30
|
+
ErrorCode,
|
|
31
|
+
InvalidRequestError,
|
|
32
|
+
JobStreamingError,
|
|
33
|
+
RateLimitError,
|
|
34
|
+
StreamCancelledError,
|
|
35
|
+
TransientNetworkError,
|
|
36
|
+
UnacknowledgedEventError,
|
|
37
|
+
)
|
|
24
38
|
from jobstreaming.model import (
|
|
25
39
|
AdapterCapabilities,
|
|
26
40
|
Compensation,
|
|
@@ -38,28 +52,38 @@ from jobstreaming.model import (
|
|
|
38
52
|
Site,
|
|
39
53
|
)
|
|
40
54
|
from jobstreaming.registry import AdapterRegistry, default_registry
|
|
41
|
-
from jobstreaming.runtime import ScrapeContext, SearchStream
|
|
55
|
+
from jobstreaming.runtime import AckMode, ScrapeContext, SearchStream
|
|
42
56
|
|
|
43
57
|
__all__ = [
|
|
44
58
|
"AdapterCapabilities",
|
|
45
59
|
"AdapterCheckpoint",
|
|
46
60
|
"AdapterRegistry",
|
|
61
|
+
"AckMode",
|
|
62
|
+
"AuthenticationConfigurationError",
|
|
63
|
+
"CheckpointCompatibilityError",
|
|
64
|
+
"CheckpointConflictError",
|
|
47
65
|
"CheckpointError",
|
|
48
66
|
"CheckpointMismatchError",
|
|
67
|
+
"CheckpointStore",
|
|
49
68
|
"Compensation",
|
|
50
69
|
"CompensationInterval",
|
|
51
70
|
"Country",
|
|
71
|
+
"CursorExpiredError",
|
|
52
72
|
"DescriptionFormat",
|
|
73
|
+
"ErrorCode",
|
|
53
74
|
"ErrorEvent",
|
|
54
75
|
"EventType",
|
|
55
76
|
"JobEvent",
|
|
56
77
|
"JobPost",
|
|
57
78
|
"JobResponse",
|
|
79
|
+
"JobStreamingError",
|
|
58
80
|
"JobType",
|
|
59
81
|
"JsonFileCheckpointStore",
|
|
82
|
+
"InvalidRequestError",
|
|
60
83
|
"Location",
|
|
61
84
|
"MemoryCheckpointStore",
|
|
62
85
|
"ProgressEvent",
|
|
86
|
+
"RateLimitError",
|
|
63
87
|
"SalarySource",
|
|
64
88
|
"ScrapeContext",
|
|
65
89
|
"Scraper",
|
|
@@ -70,6 +94,9 @@ __all__ = [
|
|
|
70
94
|
"SearchStream",
|
|
71
95
|
"Site",
|
|
72
96
|
"SiteCompleteEvent",
|
|
97
|
+
"StreamCancelledError",
|
|
98
|
+
"TransientNetworkError",
|
|
99
|
+
"UnacknowledgedEventError",
|
|
73
100
|
"WarningEvent",
|
|
74
101
|
"build_search_request",
|
|
75
102
|
"default_registry",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from collections.abc import Iterator
|
|
3
|
+
from collections.abc import Callable, Iterator
|
|
4
4
|
from pathlib import Path
|
|
5
|
+
from threading import Event
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
7
8
|
import pandas as pd
|
|
@@ -18,7 +19,7 @@ from jobstreaming.model import (
|
|
|
18
19
|
)
|
|
19
20
|
from jobstreaming.registry import AdapterRegistry, default_registry
|
|
20
21
|
from jobstreaming.result import jobs_to_dataframe
|
|
21
|
-
from jobstreaming.runtime import SearchStream
|
|
22
|
+
from jobstreaming.runtime import AckMode, SearchStream
|
|
22
23
|
from jobstreaming.util import create_logger, set_logger_level
|
|
23
24
|
|
|
24
25
|
|
|
@@ -97,6 +98,9 @@ def stream_search(
|
|
|
97
98
|
queue_size: int = 128,
|
|
98
99
|
max_retries: int = 1,
|
|
99
100
|
retry_backoff: float = 0.5,
|
|
101
|
+
ack_mode: str | AckMode = AckMode.IMPLICIT,
|
|
102
|
+
cancel_event: Event | None = None,
|
|
103
|
+
cancel_callback: Callable[[], bool] | None = None,
|
|
100
104
|
**search_options: Any,
|
|
101
105
|
) -> SearchStream:
|
|
102
106
|
if request is not None and search_options:
|
|
@@ -121,6 +125,9 @@ def stream_search(
|
|
|
121
125
|
queue_size=queue_size,
|
|
122
126
|
max_retries=max_retries,
|
|
123
127
|
retry_backoff=retry_backoff,
|
|
128
|
+
ack_mode=ack_mode,
|
|
129
|
+
cancel_event=cancel_event,
|
|
130
|
+
cancel_callback=cancel_callback,
|
|
124
131
|
)
|
|
125
132
|
|
|
126
133
|
|
|
@@ -136,8 +143,10 @@ def stream_jobs(
|
|
|
136
143
|
yield event.job
|
|
137
144
|
elif isinstance(event, ErrorEvent) and raise_on_error:
|
|
138
145
|
raise RuntimeError(
|
|
139
|
-
f"{event.site.value} failed
|
|
146
|
+
f"{event.site.value} failed [{event.code.value}]: "
|
|
147
|
+
f"{event.error_type}: {event.message}"
|
|
140
148
|
)
|
|
149
|
+
stream.ack(event)
|
|
141
150
|
|
|
142
151
|
|
|
143
152
|
def scrape_jobs(
|
|
@@ -171,6 +180,9 @@ def scrape_jobs(
|
|
|
171
180
|
raise_on_error: bool = False,
|
|
172
181
|
max_retries: int = 1,
|
|
173
182
|
retry_backoff: float = 0.5,
|
|
183
|
+
ack_mode: str | AckMode = AckMode.IMPLICIT,
|
|
184
|
+
cancel_event: Event | None = None,
|
|
185
|
+
cancel_callback: Callable[[], bool] | None = None,
|
|
174
186
|
) -> pd.DataFrame:
|
|
175
187
|
set_logger_level(verbose)
|
|
176
188
|
request = build_search_request(
|
|
@@ -206,6 +218,9 @@ def scrape_jobs(
|
|
|
206
218
|
user_agent=user_agent,
|
|
207
219
|
max_retries=max_retries,
|
|
208
220
|
retry_backoff=retry_backoff,
|
|
221
|
+
ack_mode=ack_mode,
|
|
222
|
+
cancel_event=cancel_event,
|
|
223
|
+
cancel_callback=cancel_callback,
|
|
209
224
|
) as stream:
|
|
210
225
|
for event in stream:
|
|
211
226
|
if isinstance(event, JobEvent):
|
|
@@ -213,12 +228,17 @@ def scrape_jobs(
|
|
|
213
228
|
elif isinstance(event, ErrorEvent):
|
|
214
229
|
errors.append(event)
|
|
215
230
|
create_logger(event.site.value).error(
|
|
216
|
-
"%s: %s",
|
|
231
|
+
"[%s] %s: %s",
|
|
232
|
+
event.code.value,
|
|
233
|
+
event.error_type,
|
|
234
|
+
event.message,
|
|
217
235
|
)
|
|
236
|
+
stream.ack(event)
|
|
218
237
|
|
|
219
238
|
if errors and raise_on_error:
|
|
220
239
|
first = errors[0]
|
|
221
240
|
raise RuntimeError(
|
|
222
|
-
f"{first.site.value} failed
|
|
241
|
+
f"{first.site.value} failed [{first.code.value}]: "
|
|
242
|
+
f"{first.error_type}: {first.message}"
|
|
223
243
|
)
|
|
224
244
|
return jobs_to_dataframe(jobs, request)
|
|
@@ -17,6 +17,14 @@ class CheckpointMismatchError(CheckpointError):
|
|
|
17
17
|
pass
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
class CheckpointCompatibilityError(CheckpointError):
|
|
21
|
+
"""The checkpoint or an adapter cursor uses an unsupported schema version."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CheckpointConflictError(CheckpointError):
|
|
25
|
+
"""A store rejected a save because the caller owns a stale revision."""
|
|
26
|
+
|
|
27
|
+
|
|
20
28
|
class CheckpointStore(Protocol):
|
|
21
29
|
def load(self) -> SearchCheckpoint | None: ...
|
|
22
30
|
|
|
@@ -9,8 +9,11 @@ from typing import Any, TypeAlias
|
|
|
9
9
|
|
|
10
10
|
from pydantic import Field
|
|
11
11
|
|
|
12
|
+
from jobstreaming.exception import ErrorCode
|
|
12
13
|
from jobstreaming.model import FrozenModel, JobPost, SearchRequest, Site
|
|
13
14
|
|
|
15
|
+
CHECKPOINT_VERSION = 1
|
|
16
|
+
|
|
14
17
|
|
|
15
18
|
def freeze_state(state: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
16
19
|
"""Return a deeply read-only snapshot of adapter resume state."""
|
|
@@ -93,6 +96,9 @@ class ErrorEvent:
|
|
|
93
96
|
error_type: str
|
|
94
97
|
recoverable: bool
|
|
95
98
|
resume_state: Mapping[str, Any]
|
|
99
|
+
code: ErrorCode = ErrorCode.ADAPTER_FAILURE
|
|
100
|
+
retryable: bool = False
|
|
101
|
+
reset_checkpoint: bool = False
|
|
96
102
|
type: EventType = EventType.ERROR
|
|
97
103
|
|
|
98
104
|
|
|
@@ -128,6 +134,7 @@ SearchEvent: TypeAlias = (
|
|
|
128
134
|
|
|
129
135
|
class AdapterCheckpoint(FrozenModel):
|
|
130
136
|
site: Site
|
|
137
|
+
cursor_schema_version: int = Field(default=1, ge=1)
|
|
131
138
|
state: dict[str, Any] = Field(default_factory=dict)
|
|
132
139
|
seen_job_keys: tuple[str, ...] = ()
|
|
133
140
|
emitted_count: int = 0
|
|
@@ -136,17 +143,27 @@ class AdapterCheckpoint(FrozenModel):
|
|
|
136
143
|
|
|
137
144
|
|
|
138
145
|
class SearchCheckpoint(FrozenModel):
|
|
139
|
-
version: int =
|
|
146
|
+
version: int = CHECKPOINT_VERSION
|
|
147
|
+
revision: int = Field(default=0, ge=0)
|
|
140
148
|
request_fingerprint: str
|
|
141
149
|
adapters: dict[str, AdapterCheckpoint] = Field(default_factory=dict)
|
|
142
150
|
completed: bool = False
|
|
143
151
|
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
144
152
|
|
|
145
153
|
@classmethod
|
|
146
|
-
def for_request(
|
|
154
|
+
def for_request(
|
|
155
|
+
cls,
|
|
156
|
+
request: SearchRequest,
|
|
157
|
+
cursor_schema_versions: Mapping[Site, int] | None = None,
|
|
158
|
+
) -> SearchCheckpoint:
|
|
159
|
+
versions = cursor_schema_versions or {}
|
|
147
160
|
return cls(
|
|
148
161
|
request_fingerprint=request.fingerprint(),
|
|
149
162
|
adapters={
|
|
150
|
-
site.value: AdapterCheckpoint(
|
|
163
|
+
site.value: AdapterCheckpoint(
|
|
164
|
+
site=site,
|
|
165
|
+
cursor_schema_version=versions.get(site, 1),
|
|
166
|
+
)
|
|
167
|
+
for site in request.sites
|
|
151
168
|
},
|
|
152
169
|
)
|