Class: Jets::Preheat
Class Method Summary collapse
Instance Method Summary collapse
-
#all_functions ⇒ Object
Returns: [ “posts_controller-index”, “posts_controller-show”, … ].
- #classes ⇒ Object
-
#initialize(options) ⇒ Preheat
constructor
A new instance of Preheat.
- #warm(function_name) ⇒ Object
-
#warm_all ⇒ Object
loop through all methods fo each class make the special prewarm call to keep them warm.
Constructor Details
#initialize(options) ⇒ Preheat
Returns a new instance of Preheat.
18 19 20 21 |
# File 'lib/jets/preheat.rb', line 18 def initialize() @options = # passed to Call.new options @options[:mute_output] = true if @options[:mute_output].nil? end |
Class Method Details
Instance Method Details
#all_functions ⇒ Object
Returns:
[
"posts_controller-index",
"posts_controller-show",
...
]
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jets/preheat.rb', line 48 def all_functions classes.map do |klass| tasks = klass.tasks.select { |t| t.lang == :ruby } # only prewarm ruby functions tasks.map do |task| meth = task.meth underscored = klass.to_s.underscore.gsub('/','-') "#{underscored}-#{meth}" # function_name end end.flatten.uniq.compact end |
#classes ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/jets/preheat.rb', line 60 def classes Jets::Commands::Build.app_files.map do |path| next if path.include?("preheat_job.rb") # dont want to cause an infinite loop next if path =~ %r{app/functions} # dont support app/functions class_path = path.sub(%r{.*app/\w+/},'').sub(/\.rb$/,'') class_name = class_path.classify # IE: PostsController class_name.constantize # load app/**/* class definition end.compact end |
#warm(function_name) ⇒ Object
23 24 25 |
# File 'lib/jets/preheat.rb', line 23 def warm(function_name) Jets::Commands::Call.new(function_name, '{"_prewarm": "1"}', @options).run unless ENV['TEST'] end |
#warm_all ⇒ Object
loop through all methods fo each class make the special prewarm call to keep them warm
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jets/preheat.rb', line 29 def warm_all threads = [] all_functions.each do |function_name| threads << Thread.new do warm(function_name) end end threads.each { |t| t.join } # return the funciton names so we can see in the Lambda console # the functions being prewarmed all_functions end |