From 00a20cb98d6f6a885e3a42d43c1ec6293a9b11e2 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Wed, 30 Oct 2024 13:03:34 +0800 Subject: [PATCH] * [feedback#7498] adjust job status sync logic. --- module/ci/model.php | 26 +++++++++++++++++++++++--- module/compile/control.php | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/module/ci/model.php b/module/ci/model.php index d319d3912c..8574a0aba6 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -122,12 +122,32 @@ class ciModel extends model else { $queueInfo = json_decode($response); + $buildInfo = null; if(!empty($queueInfo->executable)) { $buildUrl = $queueInfo->executable->url . 'api/json?pretty=true'; $response = common::http($buildUrl, '', array(CURLOPT_USERPWD => $userPWD)); $buildInfo = json_decode($response); - + } + elseif(stripos($response, 'not found') !== false) + { + $job = strpos($compile->pipeline, '/job/') !== false ? $compile->pipeline : '/job/' . $compile->pipeline; + $buildUrl = "{$compile->url}{$job}/api/json?depth=1"; + $response = json_decode(common::http($buildUrl, '', array(CURLOPT_USERPWD => $userPWD))); + if($response) + { + foreach($response->builds as $build) + { + if($build->queueId == $compile->queue) + { + $buildInfo = $build; + break; + } + } + } + } + if($buildInfo) + { if(!empty($buildInfo->building)) { $this->updateBuildStatus($compile, 'building'); @@ -160,8 +180,8 @@ class ciModel extends model */ public function syncCompileStatus(object $compile, int $MRID = 0): bool { - /* Max retry times is: 3. */ - if($compile->times >= 3) + /* Max retry times is: 5. */ + if($compile->times >= 5) { $this->updateBuildStatus($compile, 'failure'); diff --git a/module/compile/control.php b/module/compile/control.php index 3d20385e2e..b4146086cb 100644 --- a/module/compile/control.php +++ b/module/compile/control.php @@ -102,7 +102,7 @@ class compile extends control $build = $this->compile->getByID($buildID); $job = $this->loadModel('job')->getByID($build->job); - if(empty($build->logs) and !in_array($build->status, array('created', 'pending'))) $build->logs = $this->compile->getLogs($job, $build); + if(!in_array($build->status, array('created', 'pending'))) $build->logs = $this->compile->getLogs($job, $build); $logs = $build->logs ? str_replace(array("\r\n", "\n"), "
", $build->logs) : ''; $this->view->logs = $logs;