title: Gracefully exit heroku worker running a JS script
body: <p>I've got a node script running on a heroku worker that is scheduled to run every day at 12:30am. It's actually running repeatedly throughout the day becuase of <a href="https://devcenter.heroku.com/articles/dynos#dyno-crash-restart-policy" rel="nofollow noreferrer">heroku's restart policy</a>.</p>
  <pre><code>2021-01-26T16:53:45.336648+00:00 heroku[worker.1]: Process exited with status 0
  2021-01-26T16:53:45.370113+00:00 heroku[worker.1]: State changed from up to crashed
  </code></pre>
  <p>I've been searching online on how to gracefully shut down my node process after the script finishes but nothing has worked so far. I've had no joy with process.exit(0) or by shutting down the worker using their 'https://api.heroku.com/apps/$APP_ID_OR_NAME/dynos/$DYNO_ID_OR_NAME/actions/stop' endpoint.</p>
  <p>The code is simple. I'm getting data from a service and posting it into another service. Heroku builds the code using webpack and then runs <code>node dist/main.js</code>. It looks something like this.</p>
  <pre><code>const postAllData = async () =&gt; {
    const data = await getData();
    await postData(data);
    
    console.log(' Script finished successfully');
  };
  
  postAllData();
  </code></pre>