diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-19 23:10:38 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-19 23:10:38 +0300 |
commit | c110d110a0078f3e22594a7c447aa0e727b88d78 (patch) | |
tree | fd547d96073cdb9d95f78ba68af032b7c5a9ac71 /lib | |
parent | 34d1be9ba1f8fa0b6e97c86e033885d5ad1a6a3d (diff) | |
download | gitlab-shell-c110d110a0078f3e22594a7c447aa0e727b88d78.tar.gz |
Fix and refactor redis command
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_config.rb | 19 | ||||
-rw-r--r-- | lib/gitlab_update.rb | 17 |
2 files changed, 23 insertions, 13 deletions
diff --git a/lib/gitlab_config.rb b/lib/gitlab_config.rb index ac6cc19..ede554d 100644 --- a/lib/gitlab_config.rb +++ b/lib/gitlab_config.rb @@ -26,4 +26,23 @@ class GitlabConfig def redis @config['redis'] ||= {} end + + def redis_namespace + redis['namespace'] || 'resque:gitlab' + end + + # Build redis command to write update event in gitlab queue + def redis_command + if redis.empty? + # Default to old method of connecting to redis + # for users that haven't updated their configuration + "env -i redis-cli" + else + if redis.has_key?("socket") + "#{redis['bin']} -s #{redis['socket']}" + else + "#{redis['bin']} -h #{redis['host']} -p #{redis['port']}" + end + end + end end diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb index a486ecc..df58e8f 100644 --- a/lib/gitlab_update.rb +++ b/lib/gitlab_update.rb @@ -2,8 +2,10 @@ require_relative 'gitlab_init' require_relative 'gitlab_net' class GitlabUpdate + attr_reader :config + def initialize(repo_path, key_id, refname) - config = GitlabConfig.new + @config = GitlabConfig.new @repo_path = repo_path.strip @repo_name = repo_path @@ -17,8 +19,6 @@ class GitlabUpdate @oldrev = ARGV[1] @newrev = ARGV[2] - - @redis = config.redis end def exec @@ -53,16 +53,7 @@ class GitlabUpdate end def update_redis - if !@redis.empty? && !@redis.has_key?("socket") - redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']}" - elsif !@redis.empty? && @redis.has_key?("socket") - redis_command = "#{@redis['bin']} -s #{@redis['socket']}" - else - # Default to old method of connecting to redis for users that haven't updated their configuration - redis_command = "env -i redis-cli" - end - - command = "#{redis_command} rpush '#{@redis['namespace']}:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" + command = "#{config.redis_command} rpush '#{config.redis_namespace}:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" system(command) end end |