数据湖探索 DLI-使用SDK提交SQL作业:查询作业状态

时间:2025-06-11 15:15:00

查询作业状态

  • 相关链接

    查询作业状态

  • 示例代码
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
        private static void checkRunning(DliClient dliClient, String jobId) throws DLIException {
            while (true) {
                ShowSqlJobStatusResponse resp;
                try {
                    resp = dliClient.showSqlJobStatus(new ShowSqlJobStatusRequest().withJobId(jobId));
                } catch (Exception e) {
                    throw new DLIException("Failed to get job status by id: " + jobId, e);
                }
                String status = resp.getStatus().getValue();
                logger.info(String.format("SparkSQL Job id %s status: %s", jobId, status));
    
                if ("FINISHED".equals(status)) {
                    return;
                }
                if ("FAILED".equals(status) || "CANCELLED".equals(status)) {
                    throw new DLIException("Run job failed or cancelled, details: " + resp.getMessage());
                }
    
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    throw new DLIException("Check job running interrupted.");
                }
            }
        }
    
support.huaweicloud.com/sdkreference-dli/dli_04_0084.html