Module: Jets::Core

Extended by:
Memoist
Included in:
Jets
Defined in:
lib/jets/core.rb

Constant Summary collapse

@@call_count =

NOTE: In development this will always be 1 because the app gets reloaded. On AWS Lambda, this will be ever increasing until the container gets replaced.

0
@@prewarm_count =
0

Instance Method Summary collapse

Instance Method Details

#applicationObject



4
5
6
# File 'lib/jets/core.rb', line 4

def application
  Jets::Application.instance
end

#awsObject



12
13
14
# File 'lib/jets/core.rb', line 12

def aws
  application.aws
end

#bootObject

Load all application base classes and project classes



17
18
19
# File 'lib/jets/core.rb', line 17

def boot
  Jets::Booter.boot!
end

#build_rootObject



35
36
37
# File 'lib/jets/core.rb', line 35

def build_root
  "/tmp/jets/#{config.project_name}".freeze
end

#call_countObject



65
66
67
# File 'lib/jets/core.rb', line 65

def call_count
  @@call_count
end

#configObject



8
9
10
# File 'lib/jets/core.rb', line 8

def config
  application.config
end

#custom_domain?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/jets/core.rb', line 106

def custom_domain?
  Jets.config.domain.hosted_zone_name
end

#envObject



28
29
30
31
32
# File 'lib/jets/core.rb', line 28

def env
  env = ENV['JETS_ENV'] || 'development'
  ENV['RAILS_ENV'] = ENV['RACK_ENV'] = env
  ActiveSupport::StringInquirer.new(env)
end

#increase_call_countObject



61
62
63
# File 'lib/jets/core.rb', line 61

def increase_call_count
  @@call_count += 1
end

#increase_prewarm_countObject



70
71
72
# File 'lib/jets/core.rb', line 70

def increase_prewarm_count
  @@prewarm_count += 1
end

#load_tasksObject



50
51
52
# File 'lib/jets/core.rb', line 50

def load_tasks
  Jets::Commands::RakeTasks.load!
end

#loggerObject



40
41
42
# File 'lib/jets/core.rb', line 40

def logger
  Jets.application.config.logger
end

#on_exception(exception) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/jets/core.rb', line 97

def on_exception(exception)
  Jets::Turbine.subclasses.each do |subclass|
    reporters = subclass.on_exceptions || []
    reporters.each do |label, block|
      block.call(exception)
    end
  end
end

#onceObject



124
125
126
127
128
129
# File 'lib/jets/core.rb', line 124

def once
  boot
  override_lambda_ruby_runtime
  tmp_load!
  start_rack_server
end

#override_lambda_ruby_runtimeObject



142
143
144
# File 'lib/jets/core.rb', line 142

def override_lambda_ruby_runtime
  require "jets/overrides/lambda"
end

#poly_only?Boolean

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/jets/core.rb', line 87

def poly_only?
  return true if ENV['JETS_POLY_ONLY'] # bypass to allow rapid development of handlers
  Jets::Commands::Build.poly_only?
end

#prewarm_countObject



74
75
76
# File 'lib/jets/core.rb', line 74

def prewarm_count
  @@prewarm_count
end

#process(event, context, handler) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/jets/core.rb', line 114

def process(event, context, handler)
  if event['_prewarm']
    Jets.increase_prewarm_count
    Jets.logger.info("Prewarm request")
    {prewarmed_at: Time.now.to_s}
  else
    Jets::Processors::MainProcessor.new(event, context, handler).run
  end
end

#project_namespaceObject



78
79
80
# File 'lib/jets/core.rb', line 78

def project_namespace
  [config.project_name, config.short_env, config.env_extra].compact.join('-').gsub('_','-')
end

#rack?Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/jets/core.rb', line 82

def rack?
  path = "#{Jets.root}/rack"
  File.exist?(path) || File.symlink?(path)
end

#report_exception(exception) ⇒ Object



92
93
94
95
# File 'lib/jets/core.rb', line 92

def report_exception(exception)
  puts "DEPRECATED: report_exception. Use on_exception instead.".color(:yellow)
  on_exception(exception)
end

#rootObject



21
22
23
24
25
26
# File 'lib/jets/core.rb', line 21

def root
  # Do not memoize this method. Turbo mode can change it
  root = ENV['JETS_ROOT'].to_s
  root = Dir.pwd if root == ''
  Pathname.new(root)
end

#ruby_folderObject



146
147
148
# File 'lib/jets/core.rb', line 146

def ruby_folder
  RUBY_VERSION.split('.')[0..1].join('.') + '.0'
end

#ruby_runtimeObject

used to configure internal lambda functions current ruby runtime that user is running IE: ruby2.5 ruby2.7



153
154
155
156
# File 'lib/jets/core.rb', line 153

def ruby_runtime
  version = RUBY_VERSION.split('.')[0..1].join('.')
  "ruby#{version}"
end

#s3_event?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/jets/core.rb', line 110

def s3_event?
  !Jets::Job::Base.s3_events.empty?
end

#start_rack_server(options = {}) ⇒ Object

Megamode support



136
137
138
139
140
# File 'lib/jets/core.rb', line 136

def start_rack_server(options={})
  rack = Jets::RackServer.new(options)
  rack.start
  rack.wait_for_socket
end

#tmp_load!Object



131
132
133
# File 'lib/jets/core.rb', line 131

def tmp_load!
  Jets::TmpLoader.load!
end

#versionObject



54
55
56
# File 'lib/jets/core.rb', line 54

def version
  Jets::VERSION
end

#webpacker?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/jets/core.rb', line 45

def webpacker?
  Gem.loaded_specs.keys.include?("webpacker")
end