Repository navigation
fix: improve Space-Track data ingestion pipeline #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -158,11 +158,14 @@ def trigger_sync( | |||||||||||||||||||||||||||||||||||||||||
| type_override = next( | ||||||||||||||||||||||||||||||||||||||||||
| (t for g, t, _ in SYNC_GROUPS if g == group), None | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| count = spacetrack_service.sync_group(db, group, type_override, limit=limit) | ||||||||||||||||||||||||||||||||||||||||||
| status = spacetrack_service.sync_group(db, group, type_override, limit=limit) | ||||||||||||||||||||||||||||||||||||||||||
| return APIResponse( | ||||||||||||||||||||||||||||||||||||||||||
| success=True, | ||||||||||||||||||||||||||||||||||||||||||
| message=f"Synced group '{group}': {count} objects upserted", | ||||||||||||||||||||||||||||||||||||||||||
| data={"group": group, "upserted": count}, | ||||||||||||||||||||||||||||||||||||||||||
| success=status["failed"] == 0, | ||||||||||||||||||||||||||||||||||||||||||
| message=( | ||||||||||||||||||||||||||||||||||||||||||
| f"Synced group '{group}': {status['upserted']} upserted, " | ||||||||||||||||||||||||||||||||||||||||||
| f"{status['failed']} failed" | ||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||
| data=status, | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+161
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🐛 Proposed fix status = spacetrack_service.sync_group(db, group, type_override, limit=limit)
return APIResponse(
- success=status["failed"] == 0,
+ success=status["failed"] == 0 and not status["errors"],
message=(
f"Synced group '{group}': {status['upserted']} upserted, "
- f"{status['failed']} failed"
+ f"{status['failed']} failed"
+ + (f" — errors: {status['errors']}" if status["errors"] else "")
),
data=status,
)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def _bg_sync(): | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,18 @@ def sync_spacetrack_data(): | |
| logger.info("Executing periodic catalog synchronization...") | ||
| db = SessionLocal() | ||
| try: | ||
| spacetrack_service.sync_objects(db) | ||
| logger.info("Space-Track sync succeeded.") | ||
| status = spacetrack_service.sync_all_groups(db, limit_per_group=500) | ||
| if status["total_failed"] > 0: | ||
| logger.warning( | ||
| f"Space-Track sync completed with issues — " | ||
| f"upserted={status['total_upserted']}, failed={status['total_failed']}." | ||
| ) | ||
| else: | ||
| logger.info( | ||
| f"Space-Track sync succeeded — upserted={status['total_upserted']}." | ||
| ) | ||
|
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🤖 Prompt for AI Agents |
||
| except Exception as e: | ||
| logger.error(f"Space-Track sync task failed: {e}") | ||
| logger.error(f"Space-Track sync task failed: {e}", exc_info=True) | ||
| finally: | ||
| db.close() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
success=Truewhen the DB is unreachableWhen
sync_groupcannot reach MongoDB it returns{"failed": 0, "upserted": 0, "errors": ["db_unreachable"]}. The conditionstatus["failed"] == 0evaluates toTruebecausefailedis0, so the endpoint responds with{"success": true}despite the sync never running. Any monitoring that relies on thesuccessflag to detect infrastructure issues will silently miss DB connectivity failures.Prompt To Fix With AI