在下面的代码中,我必须发送一封关于进程状态的电子邮件,无论是完成、错误还是超时......
def check_for_forecasts
wait_until_time = Time.now + timeout.minutes
loop do
RAILS_DEFAULT_LOGGER.info "Checking if process has finished"
if find_token != 0
update_completion_status
RAILS_DEFAULT_LOGGER.info "Process has finished"
break
elsif find_error != 0
update_timed_out_field
RAILS_DEFAULT_LOGGER.info "Process has errored"
break
elsif DateTime.now > wait_until_time
update_timed_out_field
RAILS_DEFAULT_LOGGER.info "Process has timed out"
break
else
RAILS_DEFAULT_LOGGER.info "Waiting for Process to finish"
sleep(60) # if it hasn't completed then wait 1 min and try again.
end
end
end
一般来说,我们只在 .sh 文件而不是 .rb 文件中使用 linux 'mail' 命令。下面是我们如何编写“邮件”命令以在 .sh 文件中发送邮件。
mail -s "the process has been finished" abc@xyz.com<<EOM
The process has finished successfully.
EOM
有没有办法在 .rb 文件中使用简单的邮件命令?还是我必须为此安装任何宝石?
请帮忙。谢谢你。