Search code examples
node.jscronelectronscheduled-tasks

How to schedule a task in Node.js that runs after script has exited?


In writing an Electron app, I've found the need to execute a background task that will run even when the UI has exited. An installer will be distributed to different computers, so I need a way to schedule a recurring task either in the installer or in code that gets run as part of the Electron app process. I've looked into libraries like bree and agenda, but I haven't been able to find a way to schedule in the aforementioned manner with these libraries.

How would I a) extend the functionality of the installer to schedule the task with native tools like Windows Task Scheduler or b) schedule this sort of recurrent task from my Electron app?


Solution

  • if you want to change the installer, then you need to investigate custom pages in NSH language to inbuild this functionality into electron-builder installer this will be complicated

    In my work I faced similar need and set a recurring task via windows scheduler tasks just by running a process command, please have a look at my code here: https://github.com/beliaev-maksim/beta_build_downloader/blob/6b5fce4b675cc108e4048e7d65676133df0ef78e/electron_ui/js/tasks_handler.js#L61

    same could be achieved using cron on Linux systems (but have to be installed on some distributions)

    Do not forget to vote for the answer and mark as accepted if that helped you