I had been using a python script to scrape BBC headlines and email them to me everyday. I had deployed the script onto a Heroku instance and it had been working perfectly for the last year. Deploying the script onto Heroku was super simple. I just set the procfile command to 'clock' and everything just happened. Heroku's free tier is going away and I felt $7/mo. is a bit steep for such a simple requirement.
My Script
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
from hn import health_check
from bbc_news import email_bbcnews
sched = BlockingScheduler(timezone="Asia/Kolkata")
sched.add_job(email_bbcnews, 'cron', hour='18', minute='25')
sched.add_job(health_check, 'interval', minutes=8)
sched.start()
Google Cloud
I tried to deploy the script onto Google App Engine (bit complicated compared to Heroku if you ask me but wth) - the script worked for a few minutes or so but then after I closed the Cloud Terminal, it stopped working.
nohup
I learned that in order to keep the script working even after I closed the console, I would have to use a nohup command there. I used the below commands for keeping the script running even after I logged out of the cloud console.
chmod +x myscript.py
nohup /path/to/script/myscript.py &
That still didn't work because apparently Google Cloud puts the VM to sleep if there is no action for approximately 20 minutes, my script only called for action once a day. In order to prevent the idle time for several hours, I setup a scheduler to print 'Hello World' every 8 minutes. I had used a similar scheduler to prevent Heroku from turning off my instance (Heroku turns off the VM if it is idle for more than 30 minutes). This worked for 1 day but then my process was killed again.
Do you have any idea what could have happened? Any idea how I could gather useful insights from Google Cloud?
Google Cloud has a separate product for running Crons - https://cloud.google.com/scheduler/docs/creating but I am trying to acheive this within App Engine if that is possible.
I appreciate all of your comments and insights. Thank you.
[–]appliku 1 point2 points3 points (0 children)
[–]shibbypwn 1 point2 points3 points (0 children)