64 lines
1.7 KiB
JavaScript
64 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 { runPlanningDingWorkflowSyncJob } = require('../src/jobs/planningDingWorkflowSyncJob');
|
|
|
|
function parseArgs(argv) {
|
|
const options = {
|
|
full: false,
|
|
table: 'all',
|
|
chunkSize: undefined,
|
|
lookbackMinutes: undefined,
|
|
lookbackRows: undefined,
|
|
};
|
|
|
|
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) || undefined;
|
|
return;
|
|
}
|
|
if (arg.startsWith('--lookbackMinutes=')) {
|
|
options.lookbackMinutes = Number.parseInt(arg.slice('--lookbackMinutes='.length), 10) || undefined;
|
|
return;
|
|
}
|
|
if (arg.startsWith('--lookbackRows=')) {
|
|
options.lookbackRows = Number.parseInt(arg.slice('--lookbackRows='.length), 10) || undefined;
|
|
}
|
|
});
|
|
|
|
return options;
|
|
}
|
|
|
|
async function main() {
|
|
const options = parseArgs(process.argv.slice(2));
|
|
|
|
try {
|
|
console.log('[ding-workflow-sync] 开始同步钉钉流程表', options);
|
|
const result = await runPlanningDingWorkflowSyncJob('manual_cli', options);
|
|
console.log('[ding-workflow-sync] 同步完成', JSON.stringify(result, null, 2));
|
|
} catch (error) {
|
|
console.error('[ding-workflow-sync] 同步失败:', error);
|
|
process.exitCode = 1;
|
|
} finally {
|
|
await Promise.allSettled([
|
|
cloudDb.close(),
|
|
planningDb.close(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
main();
|