简体   繁体   English

Heroku dyno充电后,Twitter Bot重新启动

[英]Twitter Bot is restarting after Heroku dyno recharges

I have a twitter bot which is reading a text file and tweeting. 我有一个Twitter机器人,它正在读取文本文件并发推文。 Now, a free Heroku dyno sleeps after every 18 hours for 6 hours, after which it restarts with the same command. 现在,一个免费的Heroku测功机每18个小时就会睡6个小时,然后用相同的命令重新启动。 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; Heroku上的文件系统是临时的,不会在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. 您需要将其存储在更永久的位置,例如S3或数据库附件之一。 Redis might be suitable for this. Redis可能适用于此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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