summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-04-20 04:33:22 +0000
committerStan Hu <stanhu@gmail.com>2016-04-20 04:33:22 +0000
commitc73b6a1c593f7bbab4b09d5cf882de78f54d6f09 (patch)
tree18e52a25c25dd18e52c57f9aed979260702caf0e /lib
parent4a8db75d9de6ff5ce56be6c36e957e89971a2d42 (diff)
parent750fd3f8447c3e7a742a33f45b46b10e4d763c3e (diff)
downloadgitlab-shell-c73b6a1c593f7bbab4b09d5cf882de78f54d6f09.tar.gz
Merge branch 'aiionx/gitlab-shell-aiionx-post_receive_jid' into 'master'
Update post receive worker so it logs a unique JID in sidekiq Taken from !50. Instead of ``` 2016-04-14T03:07:32.373Z 5285 TID-osycgmlyo PostReceive JID- INFO: start 2016-04-14T03:07:32.374Z 5285 TID-osycgmlyo PostReceive JID- INFO: arguments: [...] 2016-04-14T03:07:32.534Z 5285 TID-osycgmlyo PostReceive JID- INFO: done: 0.161 sec ``` Have this log ``` 2016-04-14T03:07:32.373Z 5285 TID-osycgmlyo PostReceive JID-54b0b2f6616cae37e3e87f8a INFO: start 2016-04-14T03:07:32.374Z 5285 TID-osycgmlyo PostReceive JID-54b0b2f6616cae37e3e87f8a INFO: arguments: [...] 2016-04-14T03:07:32.534Z 5285 TID-osycgmlyo PostReceive JID-54b0b2f6616cae37e3e87f8a INFO: done: 0.161 sec ``` This way sidekiq can Log a unique JID in the sidekiq.log for PostReceive. So when parsing the logs (with logstash for example) you know it belongs to that unique job. This puts the logs in a uniform manner like the other workers that are pushed to redis (which do have a JID) For example the ProjectWebHookWorker ``` 2016-04-14T03:13:07.917Z 5285 TID-osycsh7z0 ProjectWebHookWorker JID-800085fb3cf7241fdeecc6ec INFO: start 2016-04-14T03:13:07.918Z 5285 TID-osycsh7z0 ProjectWebHookWorker JID-800085fb3cf7241fdeecc6ec INFO: arguments: [...] 2016-04-14T03:13:12.500Z 5285 TID-osycsh7z0 ProjectWebHookWorker JID-800085fb3cf7241fdeecc6ec INFO: done: 4.583 sec ``` See merge request !55
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_post_receive.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb
index ede64f2..0fff479 100644
--- a/lib/gitlab_post_receive.rb
+++ b/lib/gitlab_post_receive.rb
@@ -2,14 +2,16 @@ require_relative 'gitlab_init'
require_relative 'gitlab_net'
require 'json'
require 'base64'
+require 'securerandom'
class GitlabPostReceive
- attr_reader :config, :repo_path, :changes
+ attr_reader :config, :repo_path, :changes, :jid
def initialize(repo_path, actor, changes)
@config = GitlabConfig.new
@repo_path, @actor = repo_path.strip, actor
@changes = changes
+ @jid = SecureRandom.hex(12)
end
def exec
@@ -71,7 +73,7 @@ class GitlabPostReceive
changes = Base64.encode64(@changes)
queue = "#{config.redis_namespace}:queue:post_receive"
- msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes] })
+ msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes], 'jid' => @jid })
if system(*config.redis_command, 'rpush', queue, msg,
err: '/dev/null', out: '/dev/null')
return true