Module: Elastics::LiveReindex::Redis

Extended by:
Redis
Included in:
Redis
Defined in:
lib/elastics/admin_live_reindex.rb

Overview

private module

Constant Summary collapse

KEYS =
{ :pid     => 'elastics-reindexing-pid',
:changes => 'elastics-reindexing-changes' }

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(command, key, *args) ⇒ Object



25
26
27
28
# File 'lib/elastics/admin_live_reindex.rb', line 25

def method_missing(command, key, *args)
  return unless Conf.redis
  Conf.redis.send(command, "#{KEYS[key]}-#{Conf.app_id}", *args)
end

Instance Method Details

#initObject

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/elastics/admin_live_reindex.rb', line 34

def init
  raise MissingRedisError, 'The live-reindex feature rely on redis. Please, install redis and the "redis" gem.' \
        unless Conf.redis.class.to_s == 'Redis'
  raise MissingAppIdError, 'You must set the Elastics::Configuration.app_id, and be sure you deploy it before live-reindexing.' \
        if Conf.app_id.nil? || Conf.app_id.empty?

  if get(:pid) && (pid = get(:pid).to_i)
    message = begin
                Process.kill(0, pid)
                %(The live-reindex of "#{Conf.app_id}" is in progress (PID #{pid}).)
              rescue Errno::ESRCH
                # no process running (will reset_keys and continue)
              rescue Exception
                %(It looks like the live-reindex of "#{Conf.app_id}" is in progress (PID #{pid}). If you are sure that there is no live-reindex in progress, please run the "elastics:admin:reset_redis_keys APP_ID=#{Conf.app_id}" rake task and retry.)
              end
    raise LiveReindexInProgressError, message if message
  end

  reset_keys
  set(:pid, $$)
end

#reset_keysObject



30
31
32
# File 'lib/elastics/admin_live_reindex.rb', line 30

def reset_keys
  KEYS.keys.each { |k| del k }
end