diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb index ede64f2f45dab836a59632be34d00baaed5ce65b..0fff4794a57b5e45cd5511b6ad3cea6094e82293 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 diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb index 3c1f3625f955132cdb73ebd534336ddc4bb956cb..9d7696e017b5ece9b98140aece9a75436cc90a57 100644 --- a/spec/gitlab_post_receive_spec.rb +++ b/spec/gitlab_post_receive_spec.rb @@ -50,7 +50,7 @@ describe GitlabPostReceive do expect(gitlab_post_receive).to receive(:system).with( *[ *%w(env -i redis-cli rpush resque:gitlab:queue:post_receive), - %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}]}/, + %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}],"jid":"#{gitlab_post_receive.jid}"}/, { err: "/dev/null", out: "/dev/null" } ] ).and_return(true)