diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-27 20:52:37 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-27 20:52:37 +0400 |
commit | 552e42f634fee790a8b6ce8d6655120bb2e69e4f (patch) | |
tree | 3b3bcd44cdb5a3f03596a3d585a620778e6d2b6d | |
parent | ce0ec05c6371e055e9cc90e6239cafc015a6a69b (diff) | |
parent | 8a65229b3548a421ca6e7c41a819b40d50f7e162 (diff) |
Merge pull request #2768 from rlaneve/feature/queued-web-hooks
Updates web hooks to process via queue
-rw-r--r-- | Procfile | 2 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/web_hook.rb | 4 | ||||
-rw-r--r-- | app/workers/project_web_hook_worker.rb | 9 | ||||
-rw-r--r-- | lib/tasks/sidekiq.rake | 2 |
5 files changed, 16 insertions, 3 deletions
@@ -1,2 +1,2 @@ web: bundle exec unicorn_rails -p $PORT -worker: bundle exec sidekiq -q post_receive,mailer,system_hook,common,default +worker: bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,common,default diff --git a/app/models/project.rb b/app/models/project.rb index e521dfc93da..cb6986ce43d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -340,7 +340,7 @@ class Project < ActiveRecord::Base end def execute_hooks(data) - hooks.each { |hook| hook.execute(data) } + hooks.each { |hook| hook.async_execute(data) } end def execute_services(data) diff --git a/app/models/web_hook.rb b/app/models/web_hook.rb index df58fa93b7e..efa27f31982 100644 --- a/app/models/web_hook.rb +++ b/app/models/web_hook.rb @@ -34,4 +34,8 @@ class WebHook < ActiveRecord::Base basic_auth: {username: parsed_url.user, password: parsed_url.password}) end end + + def async_execute(data) + Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data) + end end diff --git a/app/workers/project_web_hook_worker.rb b/app/workers/project_web_hook_worker.rb new file mode 100644 index 00000000000..9f9b9b1df5f --- /dev/null +++ b/app/workers/project_web_hook_worker.rb @@ -0,0 +1,9 @@ +class ProjectWebHookWorker + include Sidekiq::Worker + + sidekiq_options queue: :project_web_hook + + def perform(hook_id, data) + WebHook.find(hook_id).execute data + end +end diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake index 01da919d7f8..0d2ec6f332c 100644 --- a/lib/tasks/sidekiq.rake +++ b/lib/tasks/sidekiq.rake @@ -6,7 +6,7 @@ namespace :sidekiq do desc "GITLAB | Start sidekiq" task :start do - run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &" + run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &" end def pidfile |