Runner API
The runner drives the crawl loop: it discovers a plugin's roots, expands refs through the expander chain, and passes each leaf to the sink.
Use run_plugin() or async_run_plugin() for a complete plugin run. They
call Source.discover() once and return a PluginRunResult containing the
individual RunResult values and their aggregate counts. Use run_crawl() or
async_run_crawl() only when the caller deliberately owns root discovery or
needs to process one known root.
All runners use the same RunConfig. Its leaf_limit is a per-root cap for
whole-plugin runs. If a later root raises a globally fatal error, earlier
roots may already have invoked on_leaf; persistence callbacks must therefore
be idempotent when retrying run_plugin() or async_run_plugin().
See also
Concepts explains the RunResult counters and the
typed plugin errors that determine runner recovery behaviour.
run_plugin
Discover and run every top-level ref exposed by a sync plugin.
This is the whole-plugin counterpart to :func:run_crawl. It calls
plugin.source.discover(client) exactly once, then processes discovered
refs in source order by delegating to :func:run_crawl.
Processing roots sequentially deliberately avoids introducing a second,
undocumented concurrency layer. Use :func:async_run_plugin for async
adapters; it preserves this root ordering while each root's leaves retain
the configured async_concurrency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin
|
CrawlPlugin[Any, Any, LeafRecordT]
|
Crawl plugin providing a source, expanders, and sink. |
required |
client
|
SyncHttpClientProtocol
|
Configured synchronous HTTP client protocol implementation. |
required |
config
|
RunConfig
|
Run configuration forwarded to each discovered root. |
required |
on_leaf
|
OnLeafCallback[LeafRecordT, object] | None
|
Optional callback forwarded to each :func: |
None
|
Returns:
| Type | Description |
|---|---|
PluginRunResult
|
A PluginRunResult containing source-order per-root outcomes and totals. |
Raises:
| Type | Description |
|---|---|
ExpansionNotReadyError
|
Propagates unchanged from a per-root
:func: |
PartialExpansionError
|
Propagates unchanged from a per-root
:func: |
ChildListUnavailableError
|
Propagates unchanged from a per-root
:func: |
AssetDownloadError
|
A Sink or Expander raised this explicitly fatal plugin error while processing a discovered root. |
Exception
|
Propagates ordinary exceptions from |
BaseException
|
KeyboardInterrupt and other fatal errors from a per-root
:func: |
Source code in src/ladon/runner.py
async_run_plugin
Discover and run every top-level ref exposed by an async plugin.
This is the whole-plugin counterpart to :func:async_run_crawl. It
awaits plugin.source.discover(client) exactly once, then processes
roots in source order. Each root retains the existing bounded concurrent
leaf processing from :func:async_run_crawl; roots are intentionally not
run concurrently so the public API has one clear concurrency boundary.
Discovery and globally-fatal per-root errors propagate unchanged rather
than being converted into a partial aggregate. Earlier roots may already
have invoked on_leaf when a later root aborts, so callbacks must be
idempotent if the caller retries the plugin.
Raises:
| Type | Description |
|---|---|
ExpansionNotReadyError
|
Propagates unchanged from a per-root
:func: |
PartialExpansionError
|
Propagates unchanged from a per-root
:func: |
ChildListUnavailableError
|
Propagates unchanged from a per-root
:func: |
AssetDownloadError
|
A Sink or Expander raised this explicitly fatal plugin error while processing a discovered root. |
BaseException
|
Cancellation and other fatal errors from a per-root
:func: |
Source code in src/ladon/async_runner.py
run_crawl
Run a single top-level ref through the plugin adapter stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_ref
|
object
|
Reference to the resource to expand. |
required |
plugin
|
CrawlPlugin[Any, Any, LeafRecordT]
|
Crawl plugin providing source, expanders, and sink. |
required |
client
|
SyncHttpClientProtocol
|
Configured synchronous HTTP client protocol implementation. |
required |
config
|
RunConfig
|
Run-level configuration (limits, flags). |
required |
on_leaf
|
OnLeafCallback[LeafRecordT, object] | None
|
Optional callback invoked after each successful leaf consume. Use this hook for DB writes, serialization, etc. Receives (leaf_record, parent_record). |
None
|
Returns:
| Type | Description |
|---|---|
RunResult
|
RunResult with counts and any per-leaf error messages. |
Raises:
| Type | Description |
|---|---|
ExpansionNotReadyError
|
Raised from any expander or the Sink. The ref (or an intermediate ref) is not ready. Caller should record the event and move on; retry on the next scheduled run. |
PartialExpansionError
|
Raised from the first expander or Sink. From non-first expanders the failing branch is isolated and recorded in RunResult.errors instead. |
ChildListUnavailableError
|
Raised from the first expander or Sink. Same isolation rule applies to non-first expanders as for PartialExpansionError. |
AssetDownloadError
|
Raised from the Sink or an Expander. This explicitly fatal plugin error propagates. |
BaseException
|
KeyboardInterrupt and other fatal errors propagate unchanged. |
ValueError
|
Plugin has no expanders configured. |
Source code in src/ladon/runner.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
async_run_crawl
Run a single top-level ref through an async plugin adapter stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_ref
|
object
|
Reference to the resource to expand. |
required |
plugin
|
AsyncCrawlPlugin[Any, Any, AsyncLeafRecordT]
|
Async crawl plugin providing expanders and sink. |
required |
client
|
AsyncHttpClientProtocol
|
Configured asynchronous HTTP client protocol implementation. |
required |
config
|
RunConfig
|
Run-level configuration (limits, concurrency). |
required |
on_leaf
|
AsyncOnLeafCallback[AsyncLeafRecordT, object] | None
|
Optional async callback invoked after each successful leaf consume. Receives (leaf_record, parent_record). |
None
|
Returns:
| Type | Description |
|---|---|
RunResult
|
RunResult with counts and any per-leaf error messages. |
Raises:
| Type | Description |
|---|---|
ExpansionNotReadyError
|
Any expander or the Sink raised this. The ref is not yet ready; retry on the next run. |
PartialExpansionError
|
Raised from the first expander or Sink. |
ChildListUnavailableError
|
Raised from the first expander or Sink. |
AssetDownloadError
|
Raised from the Sink or an Expander. This explicitly fatal plugin error propagates. |
CancelledError
|
A leaf consume or |
BaseException
|
Other fatal BaseException subclasses raised by a leaf task propagate unchanged. |
ValueError
|
Plugin has no expanders configured. |
Source code in src/ladon/async_runner.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
RunConfig
Configuration for one single-root runner invocation.
leaf_limit caps the number of leaves processed by one root; 0 means
no limit. run_plugin() applies the same cap independently to every
root discovered by its source.
async_concurrency bounds the number of concurrent leaf-processing
slots in async_run_crawl() and execute_plan() — each slot covers
the full sink.consume() + callback pair, so slow on_leaf or
on_planned_leaf callbacks reduce effective fetch concurrency. Ignored
by the synchronous runners.
Source code in src/ladon/runner.py
RunResult
Outcome of a crawl run — returned by run_crawl(), execute_plan_sync(), and execute_plan().
leaves_consumed counts leaves for which sink.consume() succeeded,
regardless of whether the applicable on_leaf or on_planned_leaf
callback also succeeded.
leaves_persisted counts leaves for which the full pipeline succeeded:
sink.consume() completed and the applicable callback completed
without raising. When no callback is supplied, leaves_persisted equals
leaves_consumed (the pipeline trivially succeeds after consume).
leaves_failed counts leaves for which sink.consume() raised a
non-fatal exception. Callback failures are NOT included here — derive them
from leaves_consumed - leaves_persisted.
The following invariant always holds::
leaves_consumed + leaves_failed == total leaves passed to Phase 3
(after leaf_limit is applied)
errors accumulates expander branch failures (Phase 1, format
"expander branch '...': ...") and leaf-level failures (Phase 3,
formats "ref[N] consume failed: ..." and
"ref[N] callback failed: ..."). A result with leaves_failed == 0
may still contain branch or callback errors — always inspect errors
for a complete picture of what went wrong.
Source code in src/ladon/runner.py
PluginRunResult
Aggregate outcome of running every top-level ref from a plugin Source.
top_refs and results have the same order and length: result i
is the outcome for discovered ref i. errors flattens each
per-root result's errors with its stable source-order index so callers can
consume a single summary without losing the individual RunResult
values.
RunConfig.leaf_limit applies independently to each top-level run,
because :func:run_plugin delegates to :func:run_crawl once per
discovered ref. A discovery failure or an exception that is globally fatal
for a root keeps the existing runner semantics and propagates instead of
returning a partial aggregate. Earlier roots may already have invoked
on_leaf when a later root aborts, so callbacks passed to
:func:run_plugin must be idempotent if the caller retries the plugin.
Source code in src/ladon/runner.py
from_runs(top_refs, results)
classmethod
Build a stable aggregate from source-order per-root outcomes.