Home > Net >  Heroku - Python integration
Heroku - Python integration

Time:02-22

I have a script that I run locally on my laptop, which polls a server and if certain criteria are met, it sends an email. I guess like a heartbeat app of sorts.

The server is a Raspberry Pi, it has a public IP address which is all working fine.

Id like to host the python script on Heroku, so that it can run without my laptop having to be on the local network or always running.

Does anyone have experience of Heroku to show me how I can have the script hosted and running constantly?

My other query is that free tiers of Heroku go to sleep after 30 mins, so would essentially stop the script until getting an http request and spin up the instance once again.

Trying to find some form of elegant solution.

Many thanks for any advice you can give,

All the best, Simon

CodePudding user response:

If you have ssh access, use screen to keep your script running.

Install screen :

sudo apt install screen

Open a new session:

screen -S session_name

Now, you can run whatever you want, then detach the session by pressing Ctrl A then D

To go back to the session at any time, first list the active sessions:

screen -ls

Then resume the session using:

screen -r session_id_name

CodePudding user response:

Different approachs would be:

1- Cloud Functions

  1. Create lambda function in a cloud provider with your python code (free tier elegible)
  2. Trigger that function every once in a while

2- Get VM on Cloud

  1. Go to AWS, GCP, etc
  2. Get a free tier VM
  3. Run server from there
  • Related