From d180d67c91365d9f7a11760f2ccbee0f59dfe361 Mon Sep 17 00:00:00 2001 From: Guan Xiying Date: Thu, 29 Jul 2021 16:13:58 +0800 Subject: [PATCH] * Adjust syncGitlabTaskStatus function. --- module/ci/model.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/module/ci/model.php b/module/ci/model.php index 56c7ce1935..0f0beeda54 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -123,25 +123,29 @@ class ciModel extends model /** * Sync gitlab task status. * - * @param int $compile + * @param object $compile * @access public * @return void */ public function syncGitlabTaskStatus($compile) { - $now = helper::now(); + $now = helper::now(); $pipeline = $this->loadModel('gitlab')->apiGetSinglePipeline($compile->server, $compile->pipeline, $compile->queue); $jobs = $this->loadModel('gitlab')->apiGetJobs($compile->server, $compile->pipeline, $compile->queue); - $log = ""; + $data = new stdclass; + $data->status = $pipeline->status; + $data->updateDate = $now; + foreach($jobs as $job) { if(empty($job->duration) or $job->duration == '') $job->duration = '-'; - $log .= ">>> Name: $job->name, Stage: $job->stage, Status: $job->status, Duration: $job->duration \r\n "; - $log .= "Web URL: web_url\" target='_blank'>$job->web_url \r\n"; - $log .= $this->transformAnsiToHtml($this->loadModel('gitlab')->apiGetJobLog($compile->server, $compile->pipeline, $job->id)); + $data->logs = ">>> Job: $job->name, Stage: $job->stage, Status: $job->status, Duration: $job->duration Sec\r\n "; + $data->logs .= "Job URL: web_url\" target='_blank'>$job->web_url \r\n"; + $data->logs .= $this->transformAnsiToHtml($this->loadModel('gitlab')->apiGetJobLog($compile->server, $compile->pipeline, $job->id)); } - $this->dao->update(TABLE_COMPILE)->set('status')->eq($pipeline->status)->set('updateDate')->eq($now)->set('logs')->eq($log)->where('id')->eq($compile->id)->exec(); + + $this->dao->update(TABLE_COMPILE)->data($data)->where('id')->eq($compile->id)->exec(); $this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($pipeline->status)->where('id')->eq($compile->job)->exec(); }