From 0ad3372437248c4e09fd434f12e7b5e19c81b09d Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Wed, 13 Dec 2023 14:25:49 +0800 Subject: [PATCH] * Adjust cron error for compile. --- module/compile/model.php | 25 ++++++++++++++----------- module/gitlab/model.php | 2 ++ module/job/model.php | 3 +-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/module/compile/model.php b/module/compile/model.php index 1944e45716..e647bd70a2 100644 --- a/module/compile/model.php +++ b/module/compile/model.php @@ -302,12 +302,14 @@ class compileModel extends model if(isset($compilePairs[$build->queueId])) continue; $data = new stdclass(); - $data->name = $job->name; - $data->job = $job->id; - $data->queue = $build->queueId; - $data->status = $build->result == 'SUCCESS' ? 'success' : 'failure'; - $data->createdBy = 'guest'; - $data->createdDate = date('Y-m-d H:i:s', $build->timestamp / 1000); + $data->name = $job->name; + $data->job = $job->id; + $data->queue = $build->queueId; + $data->status = $build->result == 'SUCCESS' ? 'success' : 'failure'; + $data->createdBy = 'guest'; + + $buildTime = is_int($build->timestamp) ? $build->timestamp / 1000 : round($build->timestamp); + $data->createdDate = date('Y-m-d H:i:s', $buildTime); $data->updateDate = $data->createdDate; $this->dao->insert(TABLE_COMPILE)->data($data)->exec(); @@ -385,7 +387,6 @@ class compileModel extends model ->leftJoin(TABLE_PIPELINE)->alias('t2')->on('t1.server=t2.id') ->where('t1.id')->eq($compile->job) ->fetch(); - if(!$job) return false; $compileID = $compile->id; @@ -404,12 +405,14 @@ class compileModel extends model } $this->loadModel('job'); - if($job->engine == 'gitlab') $compile = $this->job->execGitlabPipeline($job, $compileID); - if($job->engine == 'jenkins') $compile = $this->job->execJenkinsPipeline($job, $repo, $compileID); + $result = new stdclass(); + if($job->engine == 'gitlab') $result = $this->job->execGitlabPipeline($job, $compileID); + if($job->engine == 'jenkins') $result = $this->job->execJenkinsPipeline($job, $repo, $compileID); + if(!$result) return false; - $this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec(); + $this->dao->update(TABLE_COMPILE)->data($result)->where('id')->eq($compileID)->exec(); $this->dao->update(TABLE_JOB) - ->set('lastStatus')->eq($compile->status) + ->set('lastStatus')->eq($result->status) ->set('lastExec')->eq($compile->updateDate) ->where('id')->eq($job->id) ->exec(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 72a417d121..174d6f6ed2 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -553,6 +553,8 @@ class gitlabModel extends model /* Also use `per_page=20` to fetch users in API. Fetch active users only. */ $url = sprintf($apiRoot, "/users") . "&order_by={$order}&sort={$sort}&page={$page}&per_page={$perPage}&active=true"; $httpData = commonModel::http($url, null, array(), array(), 'data', 'GET', 30, true, false); + if(empty($httpData['body'])) break; + $result = json_decode($httpData['body']); if(!empty($result) && is_array($result)) { diff --git a/module/job/model.php b/module/job/model.php index 40338a8b5c..b11e4df13c 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -600,8 +600,7 @@ class jobModel extends model if(!empty($variables)) $pipelineParams->variables = $variables; - $compile = new stdclass; - + $compile = new stdclass(); $pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $pipeline->project, $pipelineParams); if(empty($pipeline->id)) {