fix: add historical import jobs to unified jobs list
Historical import jobs were not appearing in the recent jobs list because list_letzshop_jobs() only queried marketplace_import_jobs and letzshop_sync_logs. Changes: - Add LetzshopHistoricalImportJob query to list_letzshop_jobs() - Add current_phase and error_message fields to LetzshopJobItem schema - Fixed stuck job 8 (marked as failed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -556,11 +556,42 @@ class LetzshopOrderService:
|
|||||||
"""
|
"""
|
||||||
List unified Letzshop-related jobs for a vendor.
|
List unified Letzshop-related jobs for a vendor.
|
||||||
|
|
||||||
Combines product imports from marketplace_import_jobs and
|
Combines product imports, historical order imports, and order syncs.
|
||||||
order syncs from letzshop_sync_logs.
|
|
||||||
"""
|
"""
|
||||||
jobs = []
|
jobs = []
|
||||||
|
|
||||||
|
# Historical order imports from letzshop_historical_import_jobs
|
||||||
|
if job_type in (None, "historical_import"):
|
||||||
|
hist_query = self.db.query(LetzshopHistoricalImportJob).filter(
|
||||||
|
LetzshopHistoricalImportJob.vendor_id == vendor_id,
|
||||||
|
)
|
||||||
|
if status:
|
||||||
|
hist_query = hist_query.filter(
|
||||||
|
LetzshopHistoricalImportJob.status == status
|
||||||
|
)
|
||||||
|
|
||||||
|
hist_jobs = hist_query.order_by(
|
||||||
|
LetzshopHistoricalImportJob.created_at.desc()
|
||||||
|
).all()
|
||||||
|
|
||||||
|
for job in hist_jobs:
|
||||||
|
jobs.append(
|
||||||
|
{
|
||||||
|
"id": job.id,
|
||||||
|
"type": "historical_import",
|
||||||
|
"status": job.status,
|
||||||
|
"created_at": job.created_at,
|
||||||
|
"started_at": job.started_at,
|
||||||
|
"completed_at": job.completed_at,
|
||||||
|
"records_processed": job.orders_processed or 0,
|
||||||
|
"records_succeeded": (job.orders_imported or 0)
|
||||||
|
+ (job.orders_updated or 0),
|
||||||
|
"records_failed": job.orders_skipped or 0,
|
||||||
|
"current_phase": job.current_phase,
|
||||||
|
"error_message": job.error_message,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# Product imports from marketplace_import_jobs
|
# Product imports from marketplace_import_jobs
|
||||||
if job_type in (None, "import"):
|
if job_type in (None, "import"):
|
||||||
import_query = self.db.query(MarketplaceImportJob).filter(
|
import_query = self.db.query(MarketplaceImportJob).filter(
|
||||||
|
|||||||
@@ -397,10 +397,12 @@ class LetzshopVendorListResponse(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class LetzshopJobItem(BaseModel):
|
class LetzshopJobItem(BaseModel):
|
||||||
"""Schema for a unified job item (import, export, or order sync)."""
|
"""Schema for a unified job item (import, export, order sync, or historical import)."""
|
||||||
|
|
||||||
id: int
|
id: int
|
||||||
type: str = Field(..., description="Job type: import, export, or order_sync")
|
type: str = Field(
|
||||||
|
..., description="Job type: import, export, order_sync, or historical_import"
|
||||||
|
)
|
||||||
status: str = Field(..., description="Job status")
|
status: str = Field(..., description="Job status")
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
started_at: datetime | None = None
|
started_at: datetime | None = None
|
||||||
@@ -408,6 +410,11 @@ class LetzshopJobItem(BaseModel):
|
|||||||
records_processed: int = 0
|
records_processed: int = 0
|
||||||
records_succeeded: int = 0
|
records_succeeded: int = 0
|
||||||
records_failed: int = 0
|
records_failed: int = 0
|
||||||
|
# Historical import specific fields
|
||||||
|
current_phase: str | None = Field(
|
||||||
|
None, description="Current phase for historical imports"
|
||||||
|
)
|
||||||
|
error_message: str | None = Field(None, description="Error message if failed")
|
||||||
|
|
||||||
|
|
||||||
class LetzshopJobsListResponse(BaseModel):
|
class LetzshopJobsListResponse(BaseModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user