Module: Jets::Core

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

Constant Summary collapse

@@extra_warning_shown =
false
@@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



47
48
49
# File 'lib/jets/core.rb', line 47

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

#call_countObject



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

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)


118
119
120
# File 'lib/jets/core.rb', line 118

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

#extraObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/jets/core.rb', line 36

def extra
  # Keep for backwards compatibility
  unless ENV['JETS_ENV_EXTRA'].blank?
    puts "DEPRECATION WARNING: JETS_ENV_EXTRA is deprecated. Use JETS_EXTRA instead.".color(:yellow) unless @@extra_warning_shown
    @@extra_warning_shown = true
    extra = ENV['JETS_ENV_EXTRA']
  end
  extra = ENV['JETS_EXTRA'] unless ENV['JETS_EXTRA'].blank?
  extra
end

#increase_call_countObject



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

def increase_call_count
  @@call_count += 1
end

#increase_prewarm_countObject



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

def increase_prewarm_count
  @@prewarm_count += 1
end

#load_tasksObject



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

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

#loggerObject



52
53
54
# File 'lib/jets/core.rb', line 52

def logger
  Jets.application.config.logger
end

#on_exception(exception) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/jets/core.rb', line 109

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



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

def once
  boot
  override_lambda_ruby_runtime
  tmp_load!
  start_rack_server
end

#override_lambda_ruby_runtimeObject



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

def override_lambda_ruby_runtime
  require "jets/overrides/lambda"
end

#poly_only?Boolean

Returns:

  • (Boolean)


99
100
101
102
# File 'lib/jets/core.rb', line 99

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



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

def prewarm_count
  @@prewarm_count
end

#process(event, context, handler) ⇒ Object



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

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



90
91
92
# File 'lib/jets/core.rb', line 90

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

#rack?Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/jets/core.rb', line 94

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

#report_exception(exception) ⇒ Object



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

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



158
159
160
# File 'lib/jets/core.rb', line 158

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



165
166
167
168
# File 'lib/jets/core.rb', line 165

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

#s3_event?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/jets/core.rb', line 122

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

#start_rack_server(options = {}) ⇒ Object

Megamode support



148
149
150
151
152
# File 'lib/jets/core.rb', line 148

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

#tmp_load!Object



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

def tmp_load!
  Jets::TmpLoader.load!
end

#versionObject



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

def version
  Jets::VERSION
end

#webpacker?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/jets/core.rb', line 57

def webpacker?
  Gem.loaded_specs.keys.any?{|k| k.start_with?("webpacker")}
end