fix(subgraph): batch idempotency, jsonl checkpoint, resume support#2
Merged
Conversation
- Add n_wallets field to CollectorResult to carry wallet count from upsert - _upsert_trades now returns (trades, wallets) tuple - _subgraph_batch checks trades table before fetching; skips markets with existing trades that resolved >24h ago (log: subgraph_skip_already_collected)
- _write_progress(): append-only jsonl, one line per market with market_id, status, trades_count, wallets_count, duration_ms, ts - _load_resume_set(): reads checkpoint, returns set of ok market_ids - _subgraph_batch: loads resume set on start, skips already-ok markets, writes checkpoint entry after every market (ok/skipped/failed) - config: add extra='ignore' to Settings to tolerate unknown env vars
- TestJsonlCheckpoint: 4 tests for _write_progress (schema, append, one-line-per-call) - TestLoadResumeSet: 4 tests for _load_resume_set (empty file, ok-only filter, malformed lines) - test_batch_skips_already_collected_markets: collector.run never called for stale+existing market - test_batch_writes_jsonl_checkpoint: checkpoint entry has correct fields for successful market - test_batch_resumes_from_checkpoint: done markets skipped, new markets processed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_subgraph_batchnow checkstradestable before fetching — markets resolved >24h ago with existing trades are skipped withsubgraph_skip_already_collectedlog entry. Safe to restart a failed batch without re-downloading everything.logs/batch_progress.jsonlwithmarket_id,status(ok/skipped/failed),trades_count,wallets_count,duration_ms,ts. Append-only, never rewrites.status=ok. Restart picks up exactly where it left off._upsert_tradesnow returns(trades, wallets)tuple;CollectorResult.n_walletscarries it to the checkpoint.extra="ignore"onSettingsto tolerate unknown env vars (e.g.FFLOW_THEGRAPH_API_KEY_SECONDARY).Test plan
uv run pytest tests/test_batch_idempotency.py— 11/11 passeduv run pytest— 100 passed, 2 skippedDepends on: #1 (retroactive/task02c-history)
🤖 Generated with Claude Code