mirror of
https://github.com/frappe/books.git
synced 2026-08-24 02:24:17 -05:00
feat: add worker for cron job and trigger frontend action to sync data with ERPNext
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
@@ -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
@@ -48,7 +48,8 @@
|
||||
"reports/**/*.ts",
|
||||
"utils/**/*.ts",
|
||||
"tests/**/*.ts",
|
||||
"dummy/**/*.ts"
|
||||
"dummy/**/*.ts",
|
||||
"jobs/**/*.ts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user