summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2019-07-07 10:50:04 +0700
committerShinya Maeda <shinya@gitlab.com>2019-07-07 11:18:07 +0700
commit4d8c2c743b875772f92722b902cd76c67c7f5597 (patch)
treede3be6a3aeeab006239e8afb31a22c5e65c7999b /app/models
parentbd69c9197cefcb31ebabe466df005f1451ac1c46 (diff)
downloadgitlab-ce-show-pipeline-progress.tar.gz
Show pipeline progressshow-pipeline-progress
We calculate pipeline progress from the count of alive builds.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb8
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--app/models/ci/stage.rb4
3 files changed, 16 insertions, 0 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 89cc082d0bc..ff790004cfe 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -786,6 +786,14 @@ module Ci
:creating
end
+ def self.alive_ratio
+ sql = <<~SQL
+ SELECT (#{alive.select('COUNT(*)').to_sql})::float / (#{select('COUNT(*)').to_sql});
+ SQL
+
+ ActiveRecord::Base.connection.execute(sql).first.values.first
+ end
+
private
def successful_deployment_status
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 20ca4a9ab24..95b891ed58e 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -794,6 +794,10 @@ module Ci
errors ? errors.full_messages.to_sentence : ""
end
+ def progress
+ (1.0 - builds.alive_ratio) * 100.0
+ end
+
private
def ci_yaml_from_repo
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
index d90339d90dc..f2f6dec8de3 100644
--- a/app/models/ci/stage.rb
+++ b/app/models/ci/stage.rb
@@ -124,5 +124,9 @@ module Ci
def manual_playable?
blocked? || skipped?
end
+
+ def progress
+ (1.0 - builds.alive_ratio) * 100.0
+ end
end
end