Module: Jets::Core
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
- #application ⇒ Object
- #aws ⇒ Object
-
#boot(options = {}) ⇒ Object
Load all application base classes and project classes.
- #build_root ⇒ Object
- #call_count ⇒ Object
- #config ⇒ Object
- #custom_domain? ⇒ Boolean
- #default_gems_source ⇒ Object
- #env ⇒ Object
- #increase_call_count ⇒ Object
- #increase_prewarm_count ⇒ Object
- #load_tasks ⇒ Object
- #loader ⇒ Object
- #logger ⇒ Object
- #on_exception(exception) ⇒ Object
- #once ⇒ Object
- #override_lambda_ruby_runtime ⇒ Object
- #poly_only? ⇒ Boolean
- #prewarm_count ⇒ Object
- #process(event, context, handler) ⇒ Object
- #project_namespace ⇒ Object
- #rack? ⇒ Boolean
- #report_exception(exception) ⇒ Object
- #root ⇒ Object
- #s3_event? ⇒ Boolean
-
#start_rack_server(options = {}) ⇒ Object
Megamode support.
- #tmp_load! ⇒ Object
- #version ⇒ Object
- #webpacker? ⇒ Boolean
Instance Method Details
#application ⇒ Object
4 5 6 |
# File 'lib/jets/core.rb', line 4 def application Jets::Application.instance end |
#aws ⇒ Object
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(={}) Jets::Booter.boot!() end |
#build_root ⇒ Object
40 41 42 |
# File 'lib/jets/core.rb', line 40 def build_root "/tmp/jets/#{config.project_name}".freeze end |
#call_count ⇒ Object
70 71 72 |
# File 'lib/jets/core.rb', line 70 def call_count @@call_count end |
#config ⇒ Object
8 9 10 |
# File 'lib/jets/core.rb', line 8 def config application.config end |
#custom_domain? ⇒ Boolean
111 112 113 |
# File 'lib/jets/core.rb', line 111 def custom_domain? Jets.config.domain.hosted_zone_name end |
#default_gems_source ⇒ Object
147 148 149 |
# File 'lib/jets/core.rb', line 147 def default_gems_source "https://gems2.lambdagems.com" end |
#env ⇒ Object
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_count ⇒ Object
66 67 68 |
# File 'lib/jets/core.rb', line 66 def increase_call_count @@call_count += 1 end |
#increase_prewarm_count ⇒ Object
75 76 77 |
# File 'lib/jets/core.rb', line 75 def increase_prewarm_count @@prewarm_count += 1 end |
#load_tasks ⇒ Object
55 56 57 |
# File 'lib/jets/core.rb', line 55 def load_tasks Jets::Commands::RakeTasks.load! end |
#loader ⇒ Object
28 29 30 |
# File 'lib/jets/core.rb', line 28 def loader Zeitwerk::Loader.new end |
#logger ⇒ Object
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 |
#once ⇒ Object
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_runtime ⇒ Object
151 152 153 |
# File 'lib/jets/core.rb', line 151 def override_lambda_ruby_runtime require "jets/overrides/lambda" end |
#poly_only? ⇒ 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_count ⇒ Object
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_namespace ⇒ Object
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
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 |
#root ⇒ Object
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
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(={}) rack = Jets::RackServer.new() 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 |
#webpacker? ⇒ Boolean
50 51 52 |
# File 'lib/jets/core.rb', line 50 def webpacker? Gem.loaded_specs.keys.include?("webpacker") end |