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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Job::Base

perform_later, perform_now, process

Methods included from Job::Helpers::S3EventHelper

#s3_event, #s3_object

Methods included from Job::Helpers::LogEventHelper

#log_event

Methods included from Job::Helpers::KinesisEventHelper

#kinesis_data

Methods inherited from Lambda::Functions

inherited, #initialize, output_keys, subclasses

Methods included from Lambda::Dsl

#lambda_functions

Constructor Details

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

Class Method Details

.prewarm!Object

Can use this to prewarm post deploy



53
54
55
56
# File 'lib/jets/internal/app/jobs/jets/preheat_job.rb', line 53

def prewarm!
  meth = CONCURRENCY > 1 ? :torch : :warm
  perform_now(meth, quiet: true)
end

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 Jets.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