Class: Jets::PreheatJob

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

Constant Summary collapse

ENABLED =

defaults to enabled

enabled.nil? ? true : enabled
CONCURRENCY =
Jets.config.prewarm.concurrency || 2
PREWARM_RATE =
Jets.config.prewarm.rate || '30 minutes'

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

#initialize

Methods included from Lambda::Dsl

#lambda_functions

Constructor Details

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

Instance Method Details

#torchObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jets/internal/app/jobs/jets/preheat_job.rb', line 14

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



33
34
35
36
37
# File 'lib/jets/internal/app/jobs/jets/preheat_job.rb', line 33

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