通过使用Google Composer和DataProc,我被要求找到一种方法,以最少的点击次数向Ops用户提供失败作业的详细信息。我在DataProc Jobs页面上找到了这个屏幕:
而且我想知道是否有办法在作业失败的情况下通过电子邮件发送内容(包括完整日志文件的链接)?
你需要在你的email_on_failure = True
中设置DataProcSparkOperator
参数。
捕获错误时,您可以编写自己的电子邮件功能。这是我的例子,当工作失败时我们发送的松弛消息。
private void runCommand(String commandName,
String[] commandArgs) {
try (CommandContext commandContext = createCommandContext()) {
// find and run the command
SparkCommand command = commandContext.findCommand(commandName);
checkSparkResource(command.context.sc());
command.main(commandArgs);
} catch (Exception e) {
logger.error(e.getMessage(), e);
String message = "Something wrong~";
String title = "Run Job on Dataproc:" + commandName + " Fail";
String text = e.getMessage();
SlackNotifier.instance()
.error(message, title, text);
}
}