有什么方法可以在 Google DataProc 作业失败时通过电子邮件发送其作业状态?

Is there any way to email the job status of a Google DataProc job when it fails?

与 Google Composer 和 DataProc 打交道,有人要求我找到一种方法,以最少的点击次数向 Ops 用户获取失败作业的详细信息。我在 DataProc 作业页面上找到了这个屏幕:

而且我想知道是否有办法在作业失败时通过电子邮件发送内容(包括 link 到完整的日志文件)?

您需要设置email_on_failure = True argument in your 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);
    }
}