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.)
4-2-stable
Ryan LaNeve 2013-01-24 15:15:24 -05:00
parent 639b0a8715
commit 8a65229b35
5 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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