Class: Jets::CLI::Concurrency::Info

Inherits:
Base
  • Object
show all
Includes:
Lambda::Functions
Defined in:
lib/jets/cli/concurrency/info.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods included from Lambda::Functions

#lambda_functions

Methods inherited from Base

#account_limit, #initialize

Methods included from Util::Truthy

#truthy?

Methods included from Lambda::Checks

#check_deployed!, #check_workers!, #workers_deployed?

Methods inherited from Base

#initialize, #paginate, #paging_params, rescue_api_error

Methods included from Util::Logging

#log

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods included from Api

#api, #api_key

Constructor Details

This class inherits a constructor from Jets::CLI::Concurrency::Base

Instance Method Details

#account_limit_infoObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/jets/cli/concurrency/info.rb', line 70

def 
  message = <<~EOL
    Account Limits
      Concurrent Executions: #{.concurrent_executions}
      Unreserved Concurrent Executions: #{.unreserved_concurrent_executions}
  EOL
  if has_unreserved?
    message << "Functions with no reserved limit scale to Unreserved Concurrent Executions\n"
  end
  warn message
end

#concurrency_infoObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jets/cli/concurrency/info.rb', line 10

def concurrency_info
  warn "Concurrency for #{Jets.project.namespace}"

  presenter = CliFormat::Presenter.new(@options)
  presenter.empty_message = "No Lambda Functions found"
  presenter.header = ["Function"]
  presenter.header << "Reserved" if has_reserved?
  presenter.header << "Provisioned" if has_provisioned?
  concurrency_settings.each do |function_name, concurrency_info|
    row = []
    row << function_name.gsub("#{Jets.project.namespace}-", "")
    if has_reserved?
      reserved = concurrency_info[:reserved_concurrency]
      @reserved_concurrency_total ||= 0
      @reserved_concurrency_total += reserved.to_i
      row << reserved
    end
    if has_provisioned?
      provisioned = concurrency_info[:provisioned_concurrency]
      @provisioned_concurrency_total ||= 0
      @provisioned_concurrency_total += provisioned.to_i
      row << provisioned
    end
    presenter.rows << row
  end

  # Totals row
  unless presenter.rows.empty?
    totals = ["total"]
    totals << @reserved_concurrency_total if @reserved_concurrency_total
    totals << @provisioned_concurrency_total if @provisioned_concurrency_total
    presenter.rows << totals
  end
  presenter.show
end

#concurrency_settingsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jets/cli/concurrency/info.rb', line 46

def concurrency_settings
  concurrency_settings = {}

  lambda_functions.each do |lambda_function|
    concurrency_info = {
      reserved_concurrency: lambda_function.reserved_concurrency,
      provisioned_concurrency: lambda_function.provisioned_concurrency
    }
    concurrency_info.delete_if { |_, v| v.nil? }
    concurrency_settings[lambda_function.name] = concurrency_info
  end

  concurrency_settings
end

#has_provisioned?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/jets/cli/concurrency/info.rb', line 66

def has_provisioned?
  concurrency_settings.any? { |_, info| info.key?(:provisioned_concurrency) }
end

#has_reserved?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/jets/cli/concurrency/info.rb', line 62

def has_reserved?
  concurrency_settings.any? { |_, info| info.key?(:reserved_concurrency) }
end

#has_unreserved?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/jets/cli/concurrency/info.rb', line 82

def has_unreserved?
  concurrency_settings.any? { |_, info| !info.key?(:reserved_concurrency) }
end

#runObject



5
6
7
8
# File 'lib/jets/cli/concurrency/info.rb', line 5

def run
  concurrency_info
  
end