Run background process when starting electron app

#1

I am using "electron": "^5.0.0" and "node-schedule": "^1.3.2" - node-schedule. I am trying to load my job-queue when starting the electron app.

My main.js from electron looks like the following:

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()

My schedule.js looks like the following:

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
};

When using electron ., my app does not start and hangs up.

Any suggestions how to start my app and load all jobs into the queue?