简体   繁体   中英

Twitter Bot is restarting after Heroku dyno recharges

I have a twitter bot which is reading a text file and tweeting. Now, a free Heroku dyno sleeps after every 18 hours for 6 hours, after which it restarts with the same command. So, the text file is read again and the tweets are repeated.

To avoid this, everytime a line was read out of the list of lines from the file, I was removing the line from the list (after tweeting) and putting the remaining list into a new file which is then renamed to the original file.

I thought this might work, but when the dyno restarted, it started from the beginning. Am I missing something here? It would be great if someone could help me with this.

When the dyno restarts, it's a new one. The filesystem on Heroku is ephemeral and is not persisted across dynos; so your file is lost.

You need to store it somewhere more permanent - either somewhere like S3, or one of the database add-ons. Redis might be suitable for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM