Module: Flex::LiveReindex
- Defined in:
- lib/flex/live_reindex_admin.rb
Overview
Defined Under Namespace
Modules: Redis
Classes: ExtraIndexError, LiveReindexInProgressError, MissingAppIdError, MissingEnsureIndicesError, MissingOnReindexBlockError, MissingRedisError, MissingStopIndexingProcError, MultipleReindexError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#each_change ⇒ Object
Returns the value of attribute each_change.
57
58
59
|
# File 'lib/flex/live_reindex_admin.rb', line 57
def each_change
@each_change
end
|
Instance Method Details
#on_each_change(&block) ⇒ Object
54
55
56
|
# File 'lib/flex/live_reindex_admin.rb', line 54
def on_each_change(&block)
@each_change = block
end
|
#on_reindex(&block) ⇒ Object
50
51
52
|
# File 'lib/flex/live_reindex_admin.rb', line 50
def on_reindex(&block)
@reindex = block
end
|
#on_stop_indexing(&block) ⇒ Object
59
60
61
|
# File 'lib/flex/live_reindex_admin.rb', line 59
def on_stop_indexing(&block)
@stop_indexing = block
end
|
#prefix_index(index) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/flex/live_reindex_admin.rb', line 102
def prefix_index(index)
base = unprefix_index(index)
raise ExtraIndexError, "The index #{base} is missing from the :ensure_indices option. Reindexing aborted." \
if @ensure_indices && !@ensure_indices.include?(base)
prefixed = @timestamp + base
unless @indices.include?(base)
unless Flex.exist?(:index => prefixed)
config_hash[base] = {} unless config_hash.has_key?(base)
Flex.POST "/#{prefixed}", config_hash[base]
end
@indices |= [base]
end
prefixed
end
|
#reindex(opts = {}) {|_self| ... } ⇒ Object
63
64
65
66
|
# File 'lib/flex/live_reindex_admin.rb', line 63
def reindex(opts={})
yield self
perform(opts)
end
|
#reindex_indices(opts = {}) {|_self| ... } ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/flex/live_reindex_admin.rb', line 68
def reindex_indices(opts={})
yield self if block_given?
opts[:verbose] = true unless opts.has_key?(:verbose)
opts[:index] ||= opts.delete(:indices) || config_hash.keys
on_reindex do
migrate_indices(opts)
end
perform(opts)
end
|
#should_prefix_index? ⇒ Boolean
82
83
84
|
# File 'lib/flex/live_reindex_admin.rb', line 82
def should_prefix_index?
Redis.get(:pid) == $$.to_s
end
|
#should_track_change? ⇒ Boolean
86
87
88
89
|
# File 'lib/flex/live_reindex_admin.rb', line 86
def should_track_change?
pid = Redis.get(:pid)
!!pid && !(pid == $$.to_s)
end
|
#track_change(action, document) ⇒ Object
91
92
93
|
# File 'lib/flex/live_reindex_admin.rb', line 91
def track_change(action, document)
Redis.rpush(:changes, MultiJson.encode([action, document]))
end
|
#track_external_change(app_id, action, document) ⇒ Object
use this method when you are tracking the change of another app you must pass the app_id of the app being affected by the change
97
98
99
100
|
# File 'lib/flex/live_reindex_admin.rb', line 97
def track_external_change(app_id, action, document)
return unless Conf.redis
Conf.redis.rpush("#{KEYS[:changes]}-#{app_id}", MultiJson.encode([action, document]))
end
|
#unprefix_index(index) ⇒ Object
remove the (eventual) prefix
119
120
121
|
# File 'lib/flex/live_reindex_admin.rb', line 119
def unprefix_index(index)
index.sub(/^\d{14}_/, '')
end
|