每 15 分钟获取 POP3 服务器一次新邮件的最佳方法是什么?
我正在开发一个应用程序,需要每 5-15 分钟获取一个 POP3 帐户以检查新电子邮件并对其进行处理。我已经编写了所有代码,除了每 5-15 分钟自动运行的部分之外。
我正在使用 Sinatra、DataMapper 并在 Heroku 上托管,这意味着 cron 作业是不可能的,因为 Heroku 最多只提供每小时的 cron 作业。
我研究了 Delayed::Job,它本身不支持 Sinatra 和 DataMapper,但有一些解决方法 < a href="https://github.com/bmizerany/sinatra-dj" rel="nofollow" title="Sinatra 示例">两者。由于我的 Ruby 知识有限,我无法找到一种方法将这两个分支合并到一个适用于 Sinatra/DataMapper 解决方案的 Delayed::Job 中。
最初我使用 Mailman 来检查具有内置轮询并连续运行的电子邮件,但由于它不是 Rack -基于它不在 Heroku 上运行。
有关下一步该去哪里的任何指示吗?在你说:不同的网络主机之前,我应该补充一点,我真的更喜欢坚持使用 Heroku,因为它易于使用(当然,上述问题除外)。
I'm developing an app that needs to fetch a POP3 account every 5-15 minutes to check for new email and process it. I have written all the code except for the part where it automatically runs every 5-15 minutes.
I'm using Sinatra, DataMapper and hosting on Heroku which means cron jobs are out of the question, because Heroku only provides hourly cron jobs at best.
I have looked into Delayed::Job which doesn't natively support Sinatra nor DataMapper but there are workarounds for both. Since my Ruby knowledge is limited I couldn't find a way to merge these two forks into one working Delayed::Job for Sinatra/DataMapper solution.
Initially I used Mailman to check for emails which has built-in polling and runs continuously, but since it's not Rack-based it doesn't run on Heroku.
Any pointers on where to go next? Before you say: a different webhost, I should add I really prefer to stick with Heroku because of its ease of use (except of course, for the above issue).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Heroku 支持 CloudMailin
Heroku supports CloudMailin
一个简单的技巧是编写包含在循环中的代码,然后在其底部休眠任意长时间:
未经测试的示例代码...
如果它必须包含在应用程序的主体中,则使用
Thread
来包装它,以便线程完成工作。您需要弄清楚共享数据结构才能将数据传输出循环。Queue
是你的朋友。A simple trick is to write your code contained in a loop, then sleep at the bottom of it for however long you want:
Untested sample code...
If it has to be contained in the main body of the app then use a
Thread
to wrap it so the thread does the work. You'll need to figure out your shared data structures to transfer the data out of the loop.Queue
is your friend there.