summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-19 19:55:54 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-02-26 16:06:49 +0200
commiteff5746b5e7cf4075edd6d1c76fdcd24c1603bb4 (patch)
tree368bb9935f8cf3f6cbcf20c48c9f48e3456a96a2
parent5bb435d0e75ad84e2fc379208cc36a25a4574453 (diff)
downloadgitlab-ce-eff5746b5e7cf4075edd6d1c76fdcd24c1603bb4.tar.gz
Redesign plugins system
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/services/system_hooks_service.rb9
-rw-r--r--app/workers/plugin_worker.rb9
-rw-r--r--lib/gitlab/plugin.rb30
-rw-r--r--lib/tasks/plugins.rake12
4 files changed, 30 insertions, 30 deletions
diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb
index ba46c0074e4..af8c02a10b7 100644
--- a/app/services/system_hooks_service.rb
+++ b/app/services/system_hooks_service.rb
@@ -12,14 +12,7 @@ class SystemHooksService
hook.async_execute(data, 'system_hooks')
end
- # Execute external plugins
- 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
+ Gitlab::Plugin.execute_all_async(data)
end
private
diff --git a/app/workers/plugin_worker.rb b/app/workers/plugin_worker.rb
new file mode 100644
index 00000000000..34a3c8d62ac
--- /dev/null
+++ b/app/workers/plugin_worker.rb
@@ -0,0 +1,9 @@
+class PluginWorker
+ include ApplicationWorker
+
+ sidekiq_options retry: false
+
+ def perform(file_name, data)
+ Gitlab::Plugin.execute(file_name, data)
+ end
+end
diff --git a/lib/gitlab/plugin.rb b/lib/gitlab/plugin.rb
index cbc57a5cce3..9604cac4b20 100644
--- a/lib/gitlab/plugin.rb
+++ b/lib/gitlab/plugin.rb
@@ -1,25 +1,23 @@
module Gitlab
module Plugin
- def self.all
- files.map do |file|
- file_name = File.basename(file, '.rb')
+ def self.files
+ Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
+ end
- # Just give sample data to method and expect it to not crash.
- begin
- klass = Object.const_get(file_name.classify)
- 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
+ def self.execute_all_async(data)
+ files.each do |file|
+ PluginWorker.perform_async(file, data)
end
end
- def self.files
- Dir.glob(Rails.root.join('plugins', '*_plugin.rb'))
+ def self.execute(file, data)
+ # 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
diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake
index 8728e232c9c..9c9f1fece85 100644
--- a/lib/tasks/plugins.rake
+++ b/lib/tasks/plugins.rake
@@ -27,13 +27,13 @@ namespace :plugins do
task validate: :environment do
puts 'Validating plugins from /plugins directory'
- Gitlab::Plugin.all.each do |plugin|
- begin
- plugin.new.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA)
- rescue => e
- puts "- #{plugin} raised an exception during boot check. #{e}"
+ Gitlab::Plugin.files.each do |file|
+ result = Gitlab::Plugin.execute(file, Gitlab::DataBuilder::Push::SAMPLE_DATA)
+
+ if result
+ puts "* #{file} succeed (zero exit code)"
else
- puts "- #{plugin} passed validation check"
+ puts "* #{file} failure (non-zero exit code)"
end
end
end