<p>I am very new to NodeJS and trying to develop an application which acts as a scheduler that tries to fetch data from ELK and sends the processed data to another ELK. I am able to achieve the expected behaviour but after completing all the processes, scheduler job does not exists and wait for another scheduler job to come up.</p>
<p>Note: This scheduler runs every 3 minutes.</p>
<p>job.js</p>
<pre><code>const self = module.exports = {
  async schedule() {
    if (process.env.SCHEDULER == &quot;MinuteFrequency&quot;) {
      var timenow = moment().seconds(0).milliseconds(0).valueOf();
      var endtime = timenow - 60000;
      var starttime = endtime - 60000 * 3;
      //sendData is an async method
      reports.sendData(starttime, endtime, &quot;SCHEDULER&quot;);
    } 
  }
}
</code></pre>
<p>I tried various solutions such Promise.allSettled(....., Promise.resolve(true), etc, but not able to fix this.</p>
<p>As per my requirement, I want the scheduler to complete and process and exit so that I can save some resources as I am planning to deploy the application using Kubernetes cronjobs.</p>

Vishnu Chaturvedi
<p>When all your work is done, you can call <code>process.exit()</code> to cause your application to exit.</p>
<p>In this particular code, you may need to know when <code>reports.sendData()</code> is actually done before exiting.  We would have to know what that code is and/or see the code to know how to know when it is done.  Just because it's an <code>async</code> function doesn't mean it's written properly to return a promise that resolves when it's done.  If you want further help, show us the code for <code>sendData()</code> and any code that it calls too.</p>
