diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 21:07:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 21:07:48 +0300 |
commit | e20baee820ea2c76ee16980a98e8080f255d9035 (patch) | |
tree | 6e13a73bee42b7ef310850d03982faebea17a0b1 /app/models/service.rb | |
parent | 71c5863d7b1ca9836a7d7703f35750cd726a9846 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/service.rb')
-rw-r--r-- | app/models/service.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/app/models/service.rb b/app/models/service.rb index 138da0c546e..e4ae68cdaa7 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -47,6 +47,7 @@ class Service < ApplicationRecord scope :without_defaults, -> { where(default: false) } scope :by_type, -> (type) { where(type: type) } scope :templates, -> { where(template: true, type: available_services_types) } + scope :instances, -> { where(instance: true, type: available_services_types) } scope :push_hooks, -> { where(push_events: true, active: true) } scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) } @@ -260,17 +261,16 @@ class Service < ApplicationRecord self.category == :issue_tracker end - # Find all service templates; if some of them do not exist, create them - # within a transaction to perform the lowest possible SQL queries. def self.find_or_create_templates create_nonexistent_templates templates end private_class_method def self.create_nonexistent_templates - nonexistent_services = available_services_types - templates.map(&:type) + nonexistent_services = list_nonexistent_services_for(templates) return if nonexistent_services.empty? + # Create within a transaction to perform the lowest possible SQL queries. transaction do nonexistent_services.each do |service_type| service_type.constantize.create(template: true) @@ -278,6 +278,20 @@ class Service < ApplicationRecord end end + def self.find_or_initialize_instances + instances + build_nonexistent_instances + end + + private_class_method def self.build_nonexistent_instances + list_nonexistent_services_for(instances).map do |service_type| + service_type.constantize.new + end + end + + private_class_method def self.list_nonexistent_services_for(scope) + available_services_types - scope.map(&:type) + end + def self.available_services_names service_names = %w[ alerts |