Class: Jets::Commands::Clean::Log

Inherits:
Base
  • Object
show all
Extended by:
Memoist
Includes:
AwsServices
Defined in:
lib/jets/commands/clean/log.rb

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Methods inherited from Base

autocomplete, banner, dispatch, eager_load!, help_list, inherited, klass_from_namespace, namespace_from_class, namespaced_commands, perform, subclasses

Instance Method Details

#cleanObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jets/commands/clean/log.rb', line 16

def clean
  are_you_sure?("delete CloudWatch logs")

  say "Removing CloudWatch logs for #{prefix_guess}..."
  log_groups.each do |g|
    next if keep_log_group?(g.log_group_name)
    delete_log_group(g.log_group_name) unless @options[:noop]
    say "Removed log group: #{g.log_group_name}"
  end
  say "Removed CloudWatch logs for #{prefix_guess}"
end

#clean_deploysObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/jets/commands/clean/log.rb', line 32

def clean_deploys
  groups = deploy_log_groups.sort_by do |g|
    g.log_group_name
  end
  # Keep the last 2 recent log groups so we can see the deleted logic
  groups = groups[0..-3]
  groups.each do |g|
    logs.delete_log_group(log_group_name: g.log_group_name) unless @options[:noop]
  end
end

#delete_log_group(log_group_name) ⇒ Object



28
29
30
# File 'lib/jets/commands/clean/log.rb', line 28

def delete_log_group(log_group_name)
  logs.delete_log_group(log_group_name: log_group_name)
end

#deploy_log_groupsObject



43
44
45
46
47
48
# File 'lib/jets/commands/clean/log.rb', line 43

def deploy_log_groups
  log_groups.select do |g|
    !keep_log_group?(g.log_group_name) &&
    g.log_group_name.include?('jets-base-path')
  end
end