Remove import history tracking from purchase orders import script
This commit is contained in:
@@ -231,6 +231,9 @@ async function importOrders(prodConnection, localConnection) {
|
|||||||
ON DUPLICATE KEY UPDATE last_sync_timestamp = NOW()
|
ON DUPLICATE KEY UPDATE last_sync_timestamp = NOW()
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
const endTime = Date.now();
|
||||||
|
const durationSeconds = Math.round((endTime - startTime) / 1000);
|
||||||
|
|
||||||
outputProgress({
|
outputProgress({
|
||||||
status: "complete",
|
status: "complete",
|
||||||
operation: "Orders import completed",
|
operation: "Orders import completed",
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const { outputProgress, formatElapsedTime, estimateRemaining, calculateRate } =
|
|||||||
|
|
||||||
async function importPurchaseOrders(prodConnection, localConnection) {
|
async function importPurchaseOrders(prodConnection, localConnection) {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
let importHistoryId;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get last sync info
|
// Get last sync info
|
||||||
@@ -11,22 +10,6 @@ async function importPurchaseOrders(prodConnection, localConnection) {
|
|||||||
);
|
);
|
||||||
const lastSyncTime = syncInfo?.[0]?.last_sync_timestamp || '1970-01-01';
|
const lastSyncTime = syncInfo?.[0]?.last_sync_timestamp || '1970-01-01';
|
||||||
|
|
||||||
// Create import history record
|
|
||||||
const [historyResult] = await localConnection.query(`
|
|
||||||
INSERT INTO import_history (
|
|
||||||
table_name,
|
|
||||||
start_time,
|
|
||||||
is_incremental,
|
|
||||||
status
|
|
||||||
) VALUES (
|
|
||||||
'purchase_orders',
|
|
||||||
NOW(),
|
|
||||||
?,
|
|
||||||
'running'
|
|
||||||
)
|
|
||||||
`, [!!syncInfo?.[0]]);
|
|
||||||
importHistoryId = historyResult.insertId;
|
|
||||||
|
|
||||||
outputProgress({
|
outputProgress({
|
||||||
operation: "Starting purchase orders import - Initializing",
|
operation: "Starting purchase orders import - Initializing",
|
||||||
status: "running",
|
status: "running",
|
||||||
@@ -315,49 +298,15 @@ async function importPurchaseOrders(prodConnection, localConnection) {
|
|||||||
ON DUPLICATE KEY UPDATE last_sync_timestamp = NOW()
|
ON DUPLICATE KEY UPDATE last_sync_timestamp = NOW()
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Update import history with final stats
|
|
||||||
const endTime = Date.now();
|
|
||||||
const durationSeconds = Math.round((endTime - startTime) / 1000);
|
|
||||||
|
|
||||||
await localConnection.query(`
|
|
||||||
UPDATE import_history
|
|
||||||
SET
|
|
||||||
end_time = NOW(),
|
|
||||||
duration_seconds = ?,
|
|
||||||
records_added = ?,
|
|
||||||
records_updated = ?,
|
|
||||||
status = 'completed',
|
|
||||||
additional_info = JSON_OBJECT(
|
|
||||||
'total_processed', ?,
|
|
||||||
'last_sync_time', ?,
|
|
||||||
'next_sync_time', NOW()
|
|
||||||
)
|
|
||||||
WHERE id = ?
|
|
||||||
`, [durationSeconds, recordsAdded, recordsUpdated, totalItems, lastSyncTime, importHistoryId]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: "complete",
|
status: "complete",
|
||||||
totalImported: totalItems,
|
totalImported: totalItems,
|
||||||
recordsAdded,
|
recordsAdded,
|
||||||
recordsUpdated,
|
recordsUpdated,
|
||||||
durationSeconds,
|
|
||||||
incrementalUpdate: !!syncInfo?.[0]
|
incrementalUpdate: !!syncInfo?.[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Update import history with error
|
|
||||||
if (importHistoryId) {
|
|
||||||
await localConnection.query(`
|
|
||||||
UPDATE import_history
|
|
||||||
SET
|
|
||||||
end_time = NOW(),
|
|
||||||
duration_seconds = ?,
|
|
||||||
status = 'failed',
|
|
||||||
error_message = ?
|
|
||||||
WHERE id = ?
|
|
||||||
`, [Math.round((Date.now() - startTime) / 1000), error.message, importHistoryId]);
|
|
||||||
}
|
|
||||||
|
|
||||||
outputProgress({
|
outputProgress({
|
||||||
operation: "Purchase orders import failed",
|
operation: "Purchase orders import failed",
|
||||||
status: "error",
|
status: "error",
|
||||||
|
|||||||
Reference in New Issue
Block a user