Module: MovableInk::AWS::ElastiCache

Included in:
MovableInk::AWS
Defined in:
lib/movable_ink/aws/elasticache.rb

Instance Method Summary collapse

Instance Method Details

#all_elasticache_replicas(name) ⇒ Object



43
44
45
46
# File 'lib/movable_ink/aws/elasticache.rb', line 43

def all_elasticache_replicas(name)
  elasticache_replicas(name)
    .map { |replica| replica.read_endpoint.address }
end

#elasticache(region: my_region) ⇒ Object



4
5
6
7
# File 'lib/movable_ink/aws/elasticache.rb', line 4

def elasticache(region: my_region)
  @elasticache_client ||= {}
  @elasticache_client[region] ||= Aws::ElastiCache::Client.new(region: region)
end

#elasticache_primary(name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/movable_ink/aws/elasticache.rb', line 18

def elasticache_primary(name)
  replication_group(name)
    .node_groups
    .first
    .primary_endpoint
    .address
end

#elasticache_replica_in_my_az(name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/movable_ink/aws/elasticache.rb', line 48

def elasticache_replica_in_my_az(name)
  members = node_group_members_in_my_az(name)
  begin
    members
      .select{|ng| ng.current_role == 'replica'}
      .first
      .read_endpoint
      .address
  rescue NoMethodError
    members
      .first
      .read_endpoint
      .address
  end
end

#elasticache_replicas(name) ⇒ Object



38
39
40
41
# File 'lib/movable_ink/aws/elasticache.rb', line 38

def elasticache_replicas(name)
  node_group_members(name)
    .select { |ng| ng.current_role == 'replica' }
end

#node_group_members(name) ⇒ Object



26
27
28
29
30
31
# File 'lib/movable_ink/aws/elasticache.rb', line 26

def node_group_members(name)
  replication_group(name)
    .node_groups
    .first
    .node_group_members
end

#node_group_members_in_my_az(name) ⇒ Object



33
34
35
36
# File 'lib/movable_ink/aws/elasticache.rb', line 33

def node_group_members_in_my_az(name)
  node_group_members(name)
    .select { |ng| ng.preferred_availability_zone == availability_zone }
end

#replication_group(name) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/movable_ink/aws/elasticache.rb', line 9

def replication_group(name)
  run_with_backoff do
    @replication_group ||= elasticache
      .describe_replication_groups(replication_group_id: name)
      .replication_groups
      .first
  end
end