summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-08-21 12:40:06 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2019-08-21 12:40:39 +0200
commit80c90d6f87575b6569d0886ce83b6e760068f28e (patch)
tree4d56ecd6329f6da377ce046d9b6650949260900b
parent9174d60ba1ce3e183396f360c6e41ed23540b6d0 (diff)
downloadgitlab-ce-make-priority-builds.tar.gz
Allow some builds to be processed firstmake-priority-builds
This adds a scheduler_priority to consider some builds to be more important than others
-rw-r--r--app/models/ci/build.rb6
-rw-r--r--app/services/ci/register_job_service.rb8
-rw-r--r--db/migrate/20190821103353_add_priority_to_ci_builds.rb12
-rw-r--r--db/schema.rb3
4 files changed, 25 insertions, 4 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 3c0efca31db..bc796a2a0fe 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -307,6 +307,12 @@ module Ci
self.name == 'pages'
end
+ def incement_scheduler_priority!
+ if created? || pending?
+ increment!(:scheduler_priority)
+ end
+ end
+
def runnable?
true
end
diff --git a/app/services/ci/register_job_service.rb b/app/services/ci/register_job_service.rb
index 9d4cf5df713..99df63e19c6 100644
--- a/app/services/ci/register_job_service.rb
+++ b/app/services/ci/register_job_service.rb
@@ -108,13 +108,14 @@ module Ci
# this returns builds that are ordered by number of running builds
# we prefer projects that don't use shared runners at all
joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id")
- .order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC')
+ .order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.scheduler_priority DESC NULLS LAST', 'ci_builds.id ASC')
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def builds_for_project_runner
- new_builds.where(project: runner.projects.without_deleted.with_builds_enabled).order('id ASC')
+ new_builds.where(project: runner.projects.without_deleted.with_builds_enabled)
+ .order('ci_builds.scheduler_priority DESC NULLS LAST', 'ci_builds.id ASC')
end
# rubocop: enable CodeReuse/ActiveRecord
@@ -128,7 +129,8 @@ module Ci
.with_group_runners_enabled
.with_builds_enabled
.without_deleted
- new_builds.where(project: projects).order('id ASC')
+ new_builds.where(project: projects)
+ .order('ci_builds.scheduler_priority DESC NULLS LAST', 'ci_builds.id ASC')
end
# rubocop: enable CodeReuse/ActiveRecord
diff --git a/db/migrate/20190821103353_add_priority_to_ci_builds.rb b/db/migrate/20190821103353_add_priority_to_ci_builds.rb
new file mode 100644
index 00000000000..a79becc30a4
--- /dev/null
+++ b/db/migrate/20190821103353_add_priority_to_ci_builds.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddPriorityToCiBuilds < ActiveRecord::Migration[5.2]
+ DOWNTIME = false
+
+ def change
+ add_column :ci_builds, :scheduler_priority, :integer, limit: 2
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ce5fd38129a..8f606748b2f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_08_15_093949) do
+ActiveRecord::Schema.define(version: 2019_08_21_103353) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -583,6 +583,7 @@ ActiveRecord::Schema.define(version: 2019_08_15_093949) do
t.datetime_with_timezone "scheduled_at"
t.string "token_encrypted"
t.integer "upstream_pipeline_id"
+ t.integer "scheduler_priority", limit: 2
t.index ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)"
t.index ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id"
t.index ["commit_id", "artifacts_expire_at", "id"], name: "index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial", where: "(((type)::text = 'Ci::Build'::text) AND ((retried = false) OR (retried IS NULL)) AND ((name)::text = ANY (ARRAY[('sast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('sast:container'::character varying)::text, ('container_scanning'::character varying)::text, ('dast'::character varying)::text])))"