feat: add worker for cron job and trigger frontend action to sync data with ERPNext

This commit is contained in:
AbleKSaju
2025-05-30 15:58:08 +05:30
parent 8a1c742684
commit da5ca9227e
3 changed files with 47 additions and 1 deletions
+7
View File
@@ -0,0 +1,7 @@
// eslint-disable-next-line
const { parentPort } = require('worker_threads');
if (parentPort) {
// eslint-disable-next-line
parentPort.postMessage({ type: 'trigger-frontend-action' });
}
+38
View File
@@ -0,0 +1,38 @@
import Bree from 'bree';
import path from 'path';
import main from 'main';
let bree: Bree;
export async function initScheduler(interval: string) {
const jobsRoot = path.join(__dirname, '..', '..', 'jobs');
if (bree) {
await bree.stop();
}
bree = new Bree({
root: jobsRoot,
defaultExtension: 'ts',
jobs: [
{
name: 'triggerErpNextSync',
interval: interval,
worker: {
workerData: {
useTsNode: true,
},
},
},
],
worker: {
argv: ['--require', 'ts-node/register'],
},
});
bree.on('worker created', () => {
main.mainWindow?.webContents.send('trigger-frontend-action');
});
await bree.start();
}
+2 -1
View File
@@ -48,7 +48,8 @@
"reports/**/*.ts", "reports/**/*.ts",
"utils/**/*.ts", "utils/**/*.ts",
"tests/**/*.ts", "tests/**/*.ts",
"dummy/**/*.ts" "dummy/**/*.ts",
"jobs/**/*.ts"
], ],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }