Commit 19aa0aea authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Redesign plugins system

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent e8985f2f
...@@ -14,14 +14,7 @@ class SystemHooksService ...@@ -14,14 +14,7 @@ class SystemHooksService
hook.async_execute(data, 'system_hooks') hook.async_execute(data, 'system_hooks')
end end
# Execute external plugins Gitlab::Plugin.execute_all_async(data)
Gitlab::Plugin.all.each do |plugin|
begin
plugin.new.execute(data)
rescue => e
Rails.logger.warn("GitLab -> Plugins -> #{plugin.class.name} raised an axception during execution. #{e}")
end
end
end end
private private
......
class PluginWorker
include ApplicationWorker
sidekiq_options retry: false
def perform(file_name, data)
Gitlab::Plugin.execute(file_name, data)
end
end
module Gitlab module Gitlab
module Plugin module Plugin
def self.all def self.files
files.map do |file| Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
file_name = File.basename(file, '.rb') end
# Just give sample data to method and expect it to not crash. def self.execute_all_async(data)
begin files.each do |file|
klass = Object.const_get(file_name.classify) PluginWorker.perform_async(file, data)
klass.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
rescue => e
Rails.logger.warn("GitLab -> Plugins -> #{file_name} raised an exception during boot check. #{e}")
next
else
Rails.logger.info "GitLab -> Plugins -> #{file_name} passed validation check"
klass
end
end end
end end
def self.files def self.execute(file, data)
Dir.glob(Rails.root.join('plugins', '*_plugin.rb')) # TODO: Implement
#
# Reuse some code from gitlab-shell https://gitlab.com/gitlab-org/gitlab-shell/blob/master/lib/gitlab_custom_hook.rb#L40
# Pass data as STDIN (or JSON encode?)
#
# 1. Return true if 0 exit code
# 2. Return false if non-zero exit code
end end
end end
end end
...@@ -27,13 +27,13 @@ namespace :plugins do ...@@ -27,13 +27,13 @@ namespace :plugins do
task validate: :environment do task validate: :environment do
puts 'Validating plugins from /plugins directory' puts 'Validating plugins from /plugins directory'
Gitlab::Plugin.all.each do |plugin| Gitlab::Plugin.files.each do |file|
begin result = Gitlab::Plugin.execute(file, Gitlab::DataBuilder::Push::SAMPLE_DATA)
plugin.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
rescue => e if result
puts "- #{plugin} raised an exception during boot check. #{e}" puts "* #{file} succeed (zero exit code)"
else else
puts "- #{plugin} passed validation check" puts "* #{file} failure (non-zero exit code)"
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment