Skip to content

Commit

Permalink
Updates project to process web hooks async via sidekiq.
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
Ryan LaNeve committed Jan 25, 2013
1 parent 639b0a8 commit 8a65229
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def observe_push(data)
end

def execute_hooks(data)
hooks.each { |hook| hook.execute(data) }
hooks.each { |hook| hook.async_execute(data) }
end

def execute_services(data)
Expand Down
4 changes: 4 additions & 0 deletions app/models/web_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ def execute(data)
basic_auth: {username: parsed_url.user, password: parsed_url.password})
end
end

def async_execute(data)
Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data)
end
end
9 changes: 9 additions & 0 deletions app/workers/project_web_hook_worker.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/tasks/sidekiq.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a65229

Please sign in to comment.