Class: Jets::PreheatJob

Inherits:
ApplicationJob show all
Defined in:
lib/jets/internal/app/jobs/jets/preheat_job.rb

Constant Summary collapse

ENABLED =
Jets.config.prewarm.enable
CONCURRENCY =
Jets.config.prewarm.concurrency
PREWARM_RATE =
Jets.config.prewarm.rate

Instance Attribute Summary

Attributes inherited from Lambda::Functions

#context, #event, #meth

Instance Method Summary collapse

Methods inherited from Job::Base

perform_later, perform_now, process

Methods inherited from Lambda::Functions

inherited, #initialize, subclasses

Methods included from Lambda::Dsl

add_custom_resource_extensions, included, #lambda_functions

Constructor Details

This class inherits a constructor from Jets::Lambda::Functions

Instance Method Details

#torchObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jets/internal/app/jobs/jets/preheat_job.rb', line 26

def torch
  threads = []
  CONCURRENCY.times do
    threads << Thread.new do
      # intentionally calling remote lambda for concurrency
      # avoid passing the _prewarm=1 flag because we want the PreheatJob#warm
      # to run it's normal workload.
      # Do not use Jets::Preheat.warm(function_name) here as that passes the _prewarm=1.
      function_name = "jets-preheat_job-warm"
      event_json = JSON.dump(event)
      options = call_options(event[:quiet])
      Jets::Commands::Call.new(function_name, event_json, options).run unless ENV['TEST']
    end
  end
  threads.each { |t| t.join }
  "Finished prewarming your application with a concurrency of #{CONCURRENCY}."
end

#warmObject



45
46
47
48
49
# File 'lib/jets/internal/app/jobs/jets/preheat_job.rb', line 45

def warm
  options = call_options(event[:quiet])
  Jets::Preheat.warm_all(options)
  "Finished prewarming your application."
end