我正在使用"electron": "^5.0.0"
和"node-schedule": "^1.3.2"
- node-schedule。我正在尝试在启动电子应用程序时加载我的工作队列。
我main.js
的 from electron 如下所示:
async function main() {
const {
app,
BrowserWindow
} = require('electron')
const schedule = require('node-schedule');
const {
Schedule
} = require('./schedule')
let win
let sch = new Schedule()
try {
await sch.initScheduledContent()
console.log("Imported of jobs done!");
} catch (error) {
console.log(error);
}
function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600
})
win.loadFile('index.html')
win.on('closed', () => {
win = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})
}
main()
我的schedule.js
样子如下:
const schedule = require('node-schedule');
class Scheduler {
constructor(){}
randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
async initScheduledContent() {
let start = new Date()
let end = new Date()
end.setSeconds(end.getSeconds() + 20) // add 20 seconds to current time
let arr = []
const numb_jobs = 50
for (let i = 0; i < numb_jobs; i++) {
d = randomDate(start, end)
arr.push([i, d]) // job_number, date
console.log('OPEN: Job -- #' + arr[i][0] + ' -- scheduled at: ' + arr[i][1]);
schedule.scheduleJob(arr[i][1], function () {
console.log('DONE: Job -- #' + arr[i][0] + ' -- executed at: ' + arr[i][1]);
});
}
console.log("\n Number of Jobs Scheduled: " + Object.keys(this.getQueue()).length + "\n");
}
}
module.exports = {
Scheduler
};
使用时electron .
,我的应用程序无法启动并挂断。
有什么建议如何启动我的应用程序并将所有作业加载到队列中?