summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-12-07 12:29:37 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-12-07 12:29:37 +0200
commit0d5265bbec0ffec004fab0b85b81a0a1bea3b471 (patch)
tree48dcb5d19bc1c0cd29379217e94a04847657ba0d
parent2a494d99faabb3b34bbb6e57a8d93bafd4f002be (diff)
downloadgitlab-ce-0d5265bbec0ffec004fab0b85b81a0a1bea3b471.tar.gz
Execute project services asynchronously
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/models/project.rb10
-rw-r--r--app/models/service.rb4
-rw-r--r--app/workers/project_service_worker.rb9
3 files changed, 15 insertions, 8 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index daf4bdd0aad..32b0145ca24 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -390,14 +390,8 @@ class Project < ActiveRecord::Base
end
def execute_services(data)
- services.each do |service|
-
- # Call service hook only if it is active
- begin
- service.execute(data) if service.active
- rescue => e
- logger.error(e)
- end
+ services.select(&:active).each do |service|
+ service.async_execute(data)
end
end
diff --git a/app/models/service.rb b/app/models/service.rb
index c489c1e96e1..71c8aa39e45 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -82,4 +82,8 @@ class Service < ActiveRecord::Base
}
end
end
+
+ def async_execute(data)
+ Sidekiq::Client.enqueue(ProjectServiceWorker, id, data)
+ end
end
diff --git a/app/workers/project_service_worker.rb b/app/workers/project_service_worker.rb
new file mode 100644
index 00000000000..cc0a7f25664
--- /dev/null
+++ b/app/workers/project_service_worker.rb
@@ -0,0 +1,9 @@
+class ProjectServiceWorker
+ include Sidekiq::Worker
+
+ sidekiq_options queue: :project_web_hook
+
+ def perform(hook_id, data)
+ Service.find(hook_id).execute(data)
+ end
+end