Commit 8a65229b3548a421ca6e7c41a819b40d50f7e162

Authored by Ryan LaNeve
1 parent 639b0a87

Updates project to process web hooks async via sidekiq.

A new queue of "project_web_hook" is used to process web hooks asynchronously, allowing each to succeed/fail (and be retried) independently.

(Basically, project web hooks now process the same as system hooks.)
1 web: bundle exec unicorn_rails -p $PORT 1 web: bundle exec unicorn_rails -p $PORT
2 -worker: bundle exec sidekiq -q post_receive,mailer,system_hook,common,default 2 +worker: bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,common,default
app/models/project.rb
@@ -340,7 +340,7 @@ class Project < ActiveRecord::Base @@ -340,7 +340,7 @@ class Project < ActiveRecord::Base
340 end 340 end
341 341
342 def execute_hooks(data) 342 def execute_hooks(data)
343 - hooks.each { |hook| hook.execute(data) } 343 + hooks.each { |hook| hook.async_execute(data) }
344 end 344 end
345 345
346 def execute_services(data) 346 def execute_services(data)
app/models/web_hook.rb
@@ -34,4 +34,8 @@ class WebHook < ActiveRecord::Base @@ -34,4 +34,8 @@ class WebHook < ActiveRecord::Base
34 basic_auth: {username: parsed_url.user, password: parsed_url.password}) 34 basic_auth: {username: parsed_url.user, password: parsed_url.password})
35 end 35 end
36 end 36 end
  37 +
  38 + def async_execute(data)
  39 + Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data)
  40 + end
37 end 41 end
app/workers/project_web_hook_worker.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class ProjectWebHookWorker
  2 + include Sidekiq::Worker
  3 +
  4 + sidekiq_options queue: :project_web_hook
  5 +
  6 + def perform(hook_id, data)
  7 + WebHook.find(hook_id).execute data
  8 + end
  9 +end
lib/tasks/sidekiq.rake
@@ -6,7 +6,7 @@ namespace :sidekiq do @@ -6,7 +6,7 @@ namespace :sidekiq do
6 6
7 desc "GITLAB | Start sidekiq" 7 desc "GITLAB | Start sidekiq"
8 task :start do 8 task :start do
9 - 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 &" 9 + 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 &"
10 end 10 end
11 11
12 def pidfile 12 def pidfile