/shub-workflow-toolkit:shub-workflow-hcffrom shub-workflow-toolkit
Provides tools and patterns for working with ScrapyCloud Hubstorage Crawl Frontier (HCF) in shub-workflow projects. Covers FrontierTool commands (list slots, count, dump, add seeds, delete, move), HCFSeedsCrawlManager setup, and critical HCF semantics like per-slot fingerprint memory and single-writer constraints.
Ships in shub-workflow-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
shub_workflow.utils.hcf)shub_workflow/utils/hcf.py
provides FrontierTool, a standalone command line script for inspecting and handling the slots of
a crawl frontier. It wraps the optional hcf-backend
package (HCFManager for queue reads/writes, HCFPal for slot listing/counting/dumping).
pip install shub-workflow[with-hcf-backend]
hcf_backend is imported lazily: without it, the module imports fine and only fails, with an
install hint, when a frontier operation is first used.
{"fp": <seed>, "qdata": {...}}) are stored in batches.Locally it runs as is: python -m shub_workflow.utils.hcf --frontier myfrontier --list. To have it
on ScrapyCloud, add a project script that subclasses it to set the frontier name (and your project
base-script mixin, if any):
# scripts/frontier_tool.py (register it in setup.py `scripts=[...]`)
import logging
from shub_workflow.utils.hcf import FrontierTool
class MyFrontierTool(FrontierTool):
frontier_name = "myfrontier" # if omitted, --frontier is required
if __name__ == "__main__":
from shub_workflow.utils import get_kumo_loglevel
logging.basicConfig(format="%(asctime)s %(name)s [%(levelname)s]: %(message)s", level=get_kumo_loglevel())
MyFrontierTool().run()
| Command line | Effect |
|---|---|
frontier_tool.py --list | list the frontier slots |
frontier_tool.py <slot> | dump up to --max-seeds (default 100) seeds, without removing them |
frontier_tool.py <slot> --count | count the requests in the slot |
frontier_tool.py <slot> -a s1 -a s2 | add seeds (repeatable) |
frontier_tool.py <slot> --delete-batch <id> | delete batch ids (repeatable) |
frontier_tool.py <slot> --delete-slot | delete the slot (resets its fingerprint memory) |
frontier_tool.py <slot> --move <target> | move all seeds, with qdata, into the target slot |
Plus the usual script options (--frontier, --project-id, ...). Class attributes:
add_seeds_flush_size (1000), move_read_size (1000). A move deletes each source batch only after
its seeds were flushed into the target, so an interrupted move can be re-run; seeds already seen by
the target are discarded.
Extending: add your option in add_argparser_options() (always call super()), and override
run(), handling your option and falling back to super().run(). Reuse the handling methods —
add_seeds(slot, seeds, qdata=None), move_slot(src, dst), delete_batches(slot, ids),
delete_slot(slot), count_slot(slot), list_slots(), dump_slot(slot, max_seeds) — and the
hcf_manager / hcfpal properties:
class MyFrontierTool(FrontierTool):
frontier_name = "myfrontier"
def add_argparser_options(self):
super().add_argparser_options()
self.argparser.add_argument("--add-range", nargs=3, type=int, metavar=("START", "STOP", "STEP"))
def run(self):
if self.args.add_range and self.args.slot:
self.add_seeds(self.args.slot, (str(n) for n in range(*self.args.add_range)))
else:
super().run()
The tool is a standalone script for operating a frontier by hand (or from maintenance scripts that
subclass it). Workflow components — crawl managers and consumers — use HCFManager directly, as below, or the
ready-made classes of the same module.
HCFSeedsCrawlManagerBefore hand-writing a crawl manager that feeds a spider with seeds from its slot, subclass
HCFSeedsCrawlManager (same module): set name and an ENABLED_SPIDERS dict of SeedsSpiderConfig
entries (RUNNING_JOBS, SEEDS_PER_JOB, SC_UNITS), and customize through hooks. It handles the
read → delete → schedule loop, split slots (SLOT_SPLITS), job ownership and fatal outcomes.
Configuration, hooks and slot naming: references/seeds-crawl-manager.md.
A crawl manager reads seeds and passes them to spiders as arguments; a consumer (the single writer)
writes new seeds back. Both with hcf_backend.manager.HCFManager(frontier, project_id=...) (the crawl
manager side is what HCFSeedsCrawlManager already implements):
# crawl manager, inside set_parameters_gen(): read -> delete -> schedule
seeds = []
for batch in self.hcf.read(slot, seeds_wanted): # batches with at least seeds_wanted requests
seeds.extend(fp for fp, _qdata in batch["requests"])
self.hcf.delete(slot, [batch["id"]]) # deleted now: a failed job loses its seeds
for i in range(0, len(seeds), seeds_per_job):
yield {"seeds": json.dumps(seeds[i: i + seeds_per_job])}
# consumer, e.g. in post_process_input_items(): add -> flush
for seed in new_seeds:
self.hcf.add_request(slot, {"fp": seed, "qdata": {}})
self.hcf.flush(slot)
Frontier writes are slow; at scale, never let them block the consumer. The synchronous add → flush
above is fine for small projects. When the writes become the bottleneck, don't hand-roll writer
threads: mix in HCFSeedsWriterMixin (same module) and call self.write_seeds(slot, seeds):
class MyConsumer(HCFSeedsWriterMixin, IssuerScriptWithSCJobInput[MyItem]):
frontier_name = "myfrontier" # else the FRONTIER_NAME project setting
def post_process_input_items(self, spider_job, args):
...
self.write_seeds(slot, list(seeds)) # never blocks
It runs one daemon writer thread per slot behind a bounded queue (seeds_queue_size, default 20
seed lists) and drops the seeds when the queue is full, counting them in seeds/dropped/<slot>
(also seeds/enqueued/<slot>, seeds/written/<slot>). Don't make it blocking: a blocking put ties
the consumer to the frontier's pace, so it stalls for long periods, stops reading finished jobs, and
the backlog of the whole data chain grows without end. Seeds only feed future crawling, while the
consumer's items are the deliverable. For the same reason, don't delay the job's consumed tag until
its queued seeds are flushed. On a normal close it writes the queued seeds (at most
seeds_writers_stop_timeout seconds per slot); on a crash the job fails at once with its traceback
and the queued seeds are lost (non-daemon writers would keep the dead job alive until Scrapy Cloud
cancels it as stalled). Wiki: Writing without blocking the consumer.
hcf_backend.manager logs routine frontier operations; silence it in your project package __init__.py:
logging.getLogger("hcf_backend.manager").setLevel(logging.ERROR).
For the crawl manager and issuer sides, see the shub-workflow-crawl-managers and
shub-workflow-issuers skills.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub scrapinghub/shub-workflow --plugin shub-workflow-toolkit10 skills in this plugin
/scanjobs-programsUse for help using shub_workflow's scanjobs tool — scanning ScrapyCloud jobs to extract and plot data from stats, logs, items, spider args or job metadata. Also reach for it, instead of a hand-rolled job-listing script, to take a census of a spider's jobs over a time window: how many ended with each close_reason (e.g. memusage_exceeded / killed by oom), on which deployed version, with which units, alongside per-job stats such as memusage/max. Covers building a scanjobs command line (the stat/log/item/spider-arg/meta patterns, the postscript post-processor -c, the --plot mini-language, time windows, and output modes) and the predefined "programs" shortcut: the PROGRAMS dict in a project's scripts/scanjobs.py (a subclass of shub_workflow.utils.scanjobs.ScanJobs), invoked as `scanjobs.py -g <program> -v key:val`, including {var} placeholders and {{ }} escaping. Applies to any project whose scripts/scanjobs.py subclasses shub_workflow's ScanJobs./shub-workflow-architecturesUse when a developer wants help designing (or redesigning) the architecture of a shub-workflow based Scrapy Cloud project — "help me design the architecture for this project", "how should I structure the crawl managers / consumers / delivery", "which components do I need", "how do I feed my spiders from a frontier", "how do I scale this crawl", "should I use a graph manager", or when migrating a project away from a central graph manager or from spiders that read/write the frontier (Frontera). Runs an INTERACTIVE design session: interviews the developer in short rounds to uncover the requirements they haven't stated yet, maps them to the independent-agents + role-separation architecture (or to a graph manager where a short ordered sequence fits), writes a design document with roles, storage contracts, scheduling and scale knobs, checks it against known pitfalls, and then scaffolds the script skeletons for the chosen roles. Covers seeds vs url frontiers, the post-crawl data chain, downloads, keep-alive scheduling, back-pressure and recrawling.Other plugins' skills for the same job