Y
Y
Yuri Ivanov2022-04-19 17:25:42
JavaScript
Yuri Ivanov, 2022-04-19 17:25:42

How to run js file using task scheduler?

Good afternoon, tell me please
. I have a main.js file, I run it through the node main.js terminal,
but I can somehow launch the file after a certain period of time
(simulate my input in the node main.js terminal)
(wrap the contents of the file in the function and then the function to run after a set interval or the scheduler is not suitable)
I figured out how the task scheduler works, how to run functions using it, but I don’t know if it’s possible to run the file and I couldn’t google something on this topic

const scheduler = new ToadScheduler()
  const task = new Task('simple task', () => .............тут main.js файл)
  const job = new SimpleIntervalJob({ seconds: 120, }, task)
  scheduler.addSimpleIntervalJob(job)

(I plan to upload the application to Heroka, so I would like a solution that would work if uploaded to this service)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eshran, 2022-04-24
@asvici

const scheduler = new ToadScheduler()
const SSH = require('child_proccess')

const task = new Task('simple task', () => {
try{ var msg = SSH.execSync('node main.js') } catch (err){ console.error(err.toString()) }
})

const job = new SimpleIntervalJob({ seconds: 120, }, task)

scheduler.addSimpleIntervalJob(job)

If I understood you correctly, then this is the solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question