forked from lunanting/cangku
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
|
|
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
|
|
|
|
const cloudDb = require('../src/config/cloudDatabase');
|
|
const planningDb = require('../src/services/planningDatabase');
|
|
const { syncJstReferenceTables } = require('../src/services/planningJstReferenceSync');
|
|
|
|
function parseArgs(argv) {
|
|
const options = {
|
|
full: false,
|
|
table: 'all',
|
|
chunkSize: 500,
|
|
lookbackMinutes: 10,
|
|
};
|
|
|
|
argv.forEach((arg) => {
|
|
if (arg === '--full') {
|
|
options.full = true;
|
|
return;
|
|
}
|
|
if (arg.startsWith('--table=')) {
|
|
options.table = arg.slice('--table='.length);
|
|
return;
|
|
}
|
|
if (arg.startsWith('--chunkSize=')) {
|
|
options.chunkSize = Number.parseInt(arg.slice('--chunkSize='.length), 10) || options.chunkSize;
|
|
return;
|
|
}
|
|
if (arg.startsWith('--lookbackMinutes=')) {
|
|
options.lookbackMinutes = Number.parseInt(arg.slice('--lookbackMinutes='.length), 10) || options.lookbackMinutes;
|
|
}
|
|
});
|
|
|
|
return options;
|
|
}
|
|
|
|
async function main() {
|
|
const options = parseArgs(process.argv.slice(2));
|
|
|
|
try {
|
|
console.log('[jst-reference-sync] 开始同步聚水潭参考表', options);
|
|
const result = await syncJstReferenceTables({
|
|
...options,
|
|
onProgress: (payload) => {
|
|
console.log(
|
|
`[jst-reference-sync] ${payload.table} ${payload.fetchedRows}/${payload.totalRows}`
|
|
);
|
|
},
|
|
});
|
|
console.log('[jst-reference-sync] 同步完成', JSON.stringify(result, null, 2));
|
|
} catch (error) {
|
|
console.error('[jst-reference-sync] 同步失败:', error);
|
|
process.exitCode = 1;
|
|
} finally {
|
|
await Promise.allSettled([
|
|
cloudDb.close(),
|
|
planningDb.close(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
main();
|