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

#boot(options = {}) ⇒ Object

Load all application base classes and project classes



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

def boot(options={})
  Jets::Booter.boot!(options)
end

#build_rootObject



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

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

#call_countObject



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

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)


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

def custom_domain?
  Jets.config.domain.hosted_zone_name
end

#default_gems_sourceObject



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

def default_gems_source
  "https://gems2.lambdagems.com"
end

#envObject



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

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

#increase_call_countObject



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

def increase_call_count
  @@call_count += 1
end

#increase_prewarm_countObject



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

def increase_prewarm_count
  @@prewarm_count += 1
end

#load_tasksObject



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

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

#loaderObject



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

def loader
  Zeitwerk::Loader.new
end

#loggerObject



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

def logger
  Jets.application.config.logger
end

#on_exception(exception) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/jets/core.rb', line 102

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



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

def once
  boot
  override_lambda_ruby_runtime
  tmp_load!
  start_rack_server
end

#override_lambda_ruby_runtimeObject



151
152
153
# File 'lib/jets/core.rb', line 151

def override_lambda_ruby_runtime
  require "jets/overrides/lambda"
end

#poly_only?Boolean

Returns:

  • (Boolean)


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

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



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

def prewarm_count
  @@prewarm_count
end

#process(event, context, handler) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/jets/core.rb', line 119

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



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

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

#rack?Boolean

Returns:

  • (Boolean)


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

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

#report_exception(exception) ⇒ Object



97
98
99
100
# File 'lib/jets/core.rb', line 97

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

#s3_event?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/jets/core.rb', line 115

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

#start_rack_server(options = {}) ⇒ Object

Megamode support



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

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

#tmp_load!Object



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

def tmp_load!
  Jets::TmpLoader.load!
end

#versionObject



59
60
61
# File 'lib/jets/core.rb', line 59

def version
  Jets::VERSION
end

#webpacker?Boolean

Returns:

  • (Boolean)


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

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