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 ⇒ Object
Load all application base classes and project classes.
- #build_root ⇒ Object
- #call_count ⇒ Object
- #config ⇒ Object
- #custom_domain? ⇒ Boolean
- #env ⇒ Object
- #increase_call_count ⇒ Object
- #increase_prewarm_count ⇒ Object
- #load_tasks ⇒ 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
- #ruby_folder ⇒ Object
-
#ruby_runtime ⇒ Object
used to configure internal lambda functions current ruby runtime that user is running IE: ruby2.5 ruby2.7.
- #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 ⇒ 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
35 36 37 |
# File 'lib/jets/core.rb', line 35 def build_root "/tmp/jets/#{config.project_name}".freeze end |
#call_count ⇒ Object
65 66 67 |
# File 'lib/jets/core.rb', line 65 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
106 107 108 |
# File 'lib/jets/core.rb', line 106 def custom_domain? Jets.config.domain.hosted_zone_name end |
#env ⇒ Object
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_count ⇒ Object
61 62 63 |
# File 'lib/jets/core.rb', line 61 def increase_call_count @@call_count += 1 end |
#increase_prewarm_count ⇒ Object
70 71 72 |
# File 'lib/jets/core.rb', line 70 def increase_prewarm_count @@prewarm_count += 1 end |
#load_tasks ⇒ Object
50 51 52 |
# File 'lib/jets/core.rb', line 50 def load_tasks Jets::Commands::RakeTasks.load! end |
#logger ⇒ Object
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 |
#once ⇒ Object
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_runtime ⇒ Object
142 143 144 |
# File 'lib/jets/core.rb', line 142 def override_lambda_ruby_runtime require "jets/overrides/lambda" end |
#poly_only? ⇒ 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_count ⇒ Object
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_namespace ⇒ Object
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
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 |
#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 |
#ruby_folder ⇒ Object
146 147 148 |
# File 'lib/jets/core.rb', line 146 def ruby_folder RUBY_VERSION.split('.')[0..1].join('.') + '.0' end |
#ruby_runtime ⇒ Object
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
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(={}) rack = Jets::RackServer.new() 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 |
#webpacker? ⇒ Boolean
45 46 47 |
# File 'lib/jets/core.rb', line 45 def webpacker? Gem.loaded_specs.keys.any?{|k| k.start_with?("webpacker")} end |