简体   繁体   English

将输出从rake发送到电子邮件

[英]Send output from rake to email

Rails 3.1.1 and Heroku Rails 3.1.1和Heroku

I am running a few Rake-commands every night on my app that is hosted at Heroku. 我每天晚上都在Heroku上运行的应用程序上运行一些Rake命令。 The rake commands produces some puts rows that I would like to read in the morning to see how the updates performed by rake was performed. rake命令会产生一些我想在早上读取的puts行,以查看rake执行的更新是如何执行的。

Preferably, I would like this info emailed to me and this seems like it should not be too difficult, but what do I need to do? 最好,我想通过电子邮件发送给我,这似乎不应该太难,但我需要做什么?

The rake_notifier gem does not seem to be the solution, since I want the output even when the rake is successful (rake_notifier seems to only send info when the rake crashes). rake_notifier gem似乎不是解决方案,因为即使rake成功,我也想要输出(rake_notifier似乎只在rake崩溃时发送信息)。

Update: I do not know ruby well enough so I have probably missed out on very simple solutions. 更新:我不太了解ruby,所以我可能错过了非常简单的解决方案。 The problems is just as much to "gather" that data. 问题与“收集”数据同样重要。 Emailing it to me is the next step in the problem chain. 通过电子邮件发送给我是问题链中的下一步。 Right now I am only checking my logs and they are flooded with tons of other data. 现在我只检查我的日志,他们充斥着大量的其他数据。

in rake task file do the following: 在rake任务文件中执行以下操作:

log_string = "" log_string =“”
begin 开始
# type all your code here #在此输入您的所有代码
# instead of using puts use #而不是使用puts use
log_string += "print log whatever you want" + "\\n\\n" log_string + =“打印日志,无论你想要什么”+“\\ n \\ n”
rescue 拯救
# rescue ur code #rescue你的代码
end 结束
# mail your log_string through a mailer that you are using. #通过您正在使用的邮件程序邮寄您的log_string。


Hence, either your rake task is successful or not, you will get your log in your mail. 因此,无论您的佣金任务是否成功,您都可以登录邮件。
Even you can mail yourself, the error message created in rake task, and that you can define in rescue block. 即使你可以邮寄自己,在rake任务中创建的错误消息,你可以在救援块中定义。

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

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