openteam-capistrano 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,4 +8,5 @@ require "openteam/capistrano/setup_common"
8
8
  require "openteam/capistrano/setup_deploy"
9
9
  require "openteam/capistrano/setup_git"
10
10
  require "openteam/capistrano/subscriber"
11
+ require "openteam/capistrano/sunspot"
11
12
  require "openteam/capistrano/tagging"
@@ -0,0 +1,71 @@
1
+ require 'fileutils'
2
+ require 'rsolr'
3
+ require 'sunspot_solr'
4
+ require 'tmpdir'
5
+
6
+ class Solr
7
+ class Replicator
8
+ attr_accessor :remote, :local
9
+
10
+ def initialize(options)
11
+ self.remote = Solr.new options[:remote]
12
+ self.local = Solr.new options[:local]
13
+ end
14
+
15
+ def replicate
16
+ if remote.index_version == local.index_version
17
+ puts 'local and remote index versions are same, no need for replication'
18
+ else
19
+ really_replicate
20
+ end
21
+ end
22
+
23
+ private
24
+ def really_replicate
25
+ print 'wait while solr replicated '
26
+ local.send_replication_command :fetchindex, :masterUrl => "#{remote.url}/replication"
27
+ while replicating?
28
+ print '.'
29
+ sleep 0.5
30
+ end
31
+ puts ' ok'
32
+ end
33
+
34
+ def replicating?
35
+ # FIXME: cann't use details command due https://issues.apache.org/jira/browse/SOLR-3131
36
+ local.send_replication_command(:filelist, :indexversion => remote.index_version)['status'] == 'invalid indexversion'
37
+ end
38
+
39
+ def print(*args)
40
+ STDOUT.print *args
41
+ STDOUT.sync
42
+ end
43
+ end
44
+
45
+ attr_accessor :url
46
+
47
+ def initialize(url)
48
+ self.url = url
49
+ end
50
+
51
+ def index_version
52
+ send_replication_command(:details)['details']['indexVersion']
53
+ end
54
+
55
+ def send_replication_command(command, extra={})
56
+ solr.get :replication, :params => {:command => command}.merge(extra)
57
+ rescue Errno::ECONNREFUSED
58
+ STDERR.puts "!!! ensure solr started on #{url} !!!"
59
+ raise "couldn't connect to #{url}"
60
+ rescue RSolr::Error::Http => e
61
+ STDERR.puts "!!! ensure solr replication handler configured on #{url} !!!"
62
+ raise "could not find replication handler on #{url}"
63
+ end
64
+
65
+ private
66
+
67
+ def solr
68
+ @solr ||= RSolr.connect :url => url
69
+ end
70
+ end
71
+
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :sunspot do
3
+ desc "Synchronize your local solr using remote solr data"
4
+ task :pull do
5
+ set(:ruby_expression) { "puts YAML.load_file('#{current_path}/config/settings.yml')['solr']['url']" }
6
+ set(:remote_solr_url) { capture("ruby -ryaml -e \"#{ruby_expression}\"").chomp }
7
+
8
+ require File.expand_path('../solr/solr', __FILE__)
9
+
10
+ Solr::Replicator.new(:remote => remote_solr_url, :local => 'http://localhost:8982/solr').replicate
11
+ end
12
+ end
13
+ end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'openteam-capistrano'
7
- gem.version = '0.0.8'
7
+ gem.version = '0.0.9'
8
8
  gem.authors = ["OpenTeam developers"]
9
9
  gem.email = ["developers@openteam.ru"]
10
10
  gem.description = %q{OpenTeam common capistrano recipe}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openteam-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-27 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano-db-tasks
@@ -110,7 +110,9 @@ files:
110
110
  - lib/openteam/capistrano/setup_common.rb
111
111
  - lib/openteam/capistrano/setup_deploy.rb
112
112
  - lib/openteam/capistrano/setup_git.rb
113
+ - lib/openteam/capistrano/solr/solr.rb
113
114
  - lib/openteam/capistrano/subscriber.rb
115
+ - lib/openteam/capistrano/sunspot.rb
114
116
  - lib/openteam/capistrano/tagging.rb
115
117
  - openteam-capistrano.gemspec
116
118
  homepage: ''
@@ -127,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
129
  version: '0'
128
130
  segments:
129
131
  - 0
130
- hash: -3643175344437776527
132
+ hash: 2643949212493095317
131
133
  required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  none: false
133
135
  requirements:
@@ -136,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  version: '0'
137
139
  segments:
138
140
  - 0
139
- hash: -3643175344437776527
141
+ hash: 2643949212493095317
140
142
  requirements: []
141
143
  rubyforge_project:
142
144
  rubygems_version: 1.8.24