couchdb_reindexer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/couchdb_reindexer.gemspec +26 -0
- data/exe/couchdb_reindexer +59 -0
- data/lib/couchdb_reindexer/version.rb +3 -0
- data/lib/couchdb_reindexer.rb +82 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1aed801fb61c5362a7a59bd2ceb929caaeaf53a4
|
4
|
+
data.tar.gz: ce57ba40b5840beda73cce4058995e8698f39b9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfe0293a376a086ab9f4ab5444464d750a09c2dcfb41e7ba885eb88538b91c03ada5cd05cefd73bb4e3efb2aa60e52bdcba3594dc8fe7455e4a5c288ef5e453e
|
7
|
+
data.tar.gz: 204b031b9c2f5643f445552128ddb52c834df5b001eb7abf57a5a8571258b535e59f36ecf8d0da17d15932337b235935421fc1b5406365619ec78bd3fc38dd9c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jesus Urias
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Couchdb Reindexer
|
2
|
+
## Installation
|
3
|
+
|
4
|
+
Add this line to your application's Gemfile:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
gem 'couchdb_reindexer'
|
8
|
+
```
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
|
12
|
+
$ bundle
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
|
16
|
+
$ gem install couchdb_reindexer
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```
|
21
|
+
bin/couchdb_reindexer
|
22
|
+
|
23
|
+
Usage: couchdb_reindexer [options]
|
24
|
+
-u, --username [USERNAME] Username for basic auth. (e.g. 'admin')
|
25
|
+
-p, --password [PASSWORD] Password for basic auth. (e.g. 'secret')
|
26
|
+
-H, --host [HOST] CouchDB Host. (e.g. '192.168.0.1')
|
27
|
+
-P, --port [PORT] CouchDB Port. (default: 5984)
|
28
|
+
--protocol [PROTOCOL] Protocol for HTTP requests. (default: http)
|
29
|
+
-h, --help Show this message.
|
30
|
+
-R, --retries [RETRIES] Number of times to retry a request before timing out. (default: 10)
|
31
|
+
-d, --database DATABASE CouchDB database. (e.g. 'default')
|
32
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "couchdb_reindexer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "couchdb_reindexer/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "couchdb_reindexer"
|
8
|
+
spec.version = CouchdbReindexer::VERSION
|
9
|
+
spec.authors = ["Jesus Urias"]
|
10
|
+
spec.email = ["itsjesusurias@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'CouchDB indexer'
|
13
|
+
spec.description = 'Simple CouchDB views reindexer'
|
14
|
+
spec.homepage = 'https://github.com/itsjesusurias/couchdb_reindexer'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'couchdb_reindexer'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = 'Usage: couchdb_reindexer [options]'
|
11
|
+
|
12
|
+
opts.on('-u', '--username [USERNAME]', \
|
13
|
+
"Username for basic auth. (e.g. 'admin')") do |u|
|
14
|
+
options[:username] = u
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-p', '--password [PASSWORD]', \
|
18
|
+
"Password for basic auth. (e.g. 'secret')") do |p|
|
19
|
+
options[:password] = p
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on('-H', '--host [HOST]', \
|
23
|
+
"CouchDB Host. (e.g. '192.168.0.1')") do |h|
|
24
|
+
options[:host] = h
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-P', '--port [PORT]', \
|
28
|
+
'CouchDB Port. (default: 5984)') do |p|
|
29
|
+
options[:port] = p
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('--protocol [PROTOCOL]', \
|
33
|
+
'Protocol for HTTP requests. (default: http)') do |p|
|
34
|
+
options[:protocol] = p
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on('-h', '--help', 'Show this message.') do
|
38
|
+
puts opts
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-R', '--retries [RETRIES]', \
|
43
|
+
'Number of times to retry a request ' \
|
44
|
+
'before timing out. (default: 10)') do |r|
|
45
|
+
options[:retries] = r
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on('-d', '--database DATABASE', \
|
49
|
+
"CouchDB database. (e.g. 'default')") do |d|
|
50
|
+
options[:database] = d
|
51
|
+
end
|
52
|
+
|
53
|
+
if ARGV.empty?
|
54
|
+
puts opts
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
end.parse!
|
58
|
+
|
59
|
+
CouchdbReindexer::Indexer.new(options).run
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'couchdb_reindexer/version'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module CouchdbReindexer
|
7
|
+
class Indexer
|
8
|
+
attr_writer :options
|
9
|
+
|
10
|
+
@@default_options = {
|
11
|
+
database: "database",
|
12
|
+
host: "127.0.0.1",
|
13
|
+
protocol: "http",
|
14
|
+
port: "5984",
|
15
|
+
retries: 10
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize(options)
|
19
|
+
@options = @@default_options.merge!(options)
|
20
|
+
puts "***************************************************************"
|
21
|
+
puts "********************** RUNNING REINDEXER **********************"
|
22
|
+
puts "ON: #{default_url}"
|
23
|
+
puts "***************************************************************"
|
24
|
+
run
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
docs = get_docs
|
29
|
+
if docs.to_json != '[{}]'
|
30
|
+
docs = docs['rows']
|
31
|
+
docs.each do |doc|
|
32
|
+
puts "Document: #{doc['doc']['_id']}"
|
33
|
+
doc['doc']['views'].each do |view|
|
34
|
+
puts "\tRequesting view: #{doc['doc']['_id']}/_view/#{view[0]}"
|
35
|
+
response = make_request(view_uri(doc['doc']['_id'], view[0]))
|
36
|
+
if response.code == '200'
|
37
|
+
puts "\tResponse status: OK!"
|
38
|
+
else
|
39
|
+
puts "\tResponse status: Error!"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
else
|
44
|
+
puts 'The database is empty or not reachable.'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_url
|
49
|
+
"#{@options[:protocol]}://#{@options[:host]}:#{@options[:port]}/#{@options[:database]}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def docs_uri
|
53
|
+
URI.parse("#{default_url}/_all_docs?startkey=%22_design/%22&endkey=%22_design0%22&include_docs=true")
|
54
|
+
end
|
55
|
+
|
56
|
+
def view_uri(document_name, view_name)
|
57
|
+
URI.parse("#{default_url}/#{document_name}/_view/#{view_name}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_docs
|
61
|
+
docs_request = make_request(docs_uri)
|
62
|
+
docs_json = '[{}]'
|
63
|
+
docs_json = docs_request.body if docs_request.code == '200'
|
64
|
+
JSON.parse(docs_json)
|
65
|
+
end
|
66
|
+
|
67
|
+
def make_request(url, retries = 1)
|
68
|
+
raise Net::ReadTimeout if retries.negative?
|
69
|
+
request = Net::HTTP::Get.new(url)
|
70
|
+
|
71
|
+
if @options[:username] && @options[:password]
|
72
|
+
request.basic_auth @options[:username], @options[:password]
|
73
|
+
end
|
74
|
+
|
75
|
+
begin
|
76
|
+
Net::HTTP.start(url.hostname, url.port) { |http| http.request(request) }
|
77
|
+
rescue Net::ReadTimeout
|
78
|
+
make_request(url, retries - 1)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: couchdb_reindexer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jesus Urias
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Simple CouchDB views reindexer
|
42
|
+
email:
|
43
|
+
- itsjesusurias@gmail.com
|
44
|
+
executables:
|
45
|
+
- couchdb_reindexer
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- couchdb_reindexer.gemspec
|
57
|
+
- exe/couchdb_reindexer
|
58
|
+
- lib/couchdb_reindexer.rb
|
59
|
+
- lib/couchdb_reindexer/version.rb
|
60
|
+
homepage: https://github.com/itsjesusurias/couchdb_reindexer
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.6.12
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: CouchDB indexer
|
84
|
+
test_files: []
|