Running Heroku background tasks with only 1 web dyno and 0 worker dynos

后端 未结 5 1861
不知归路
不知归路 2020-12-14 02:02

I have a Python Flask app on Heroku that serves web pages but also allows certain tasks to be launched which I believe would be best structured as background tasks. As such

5条回答
  •  感动是毒
    2020-12-14 03:02

    You could use a process manager such as god or monit.

    With god, you can set up your configuration like so

    God.watch do |w|
      w.name = "app"
      w.start = "python app.py"
      w.keepalive
    end
    
    God.watch do |w|
      w.name = "worker"
      w.start = "python worker.py"
      w.keepalive
    end
    

    Then you put this in your Procfile

    god -c path/to/config.god -D
    

    By default, it automatically restarts the process if it crashes, and you can configure it to restart the app if memory usage gets too high. Check out the documentation.

提交回复
热议问题