jets 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0431191b2ee4bd922dfbb1d04ded0d27c80b9d7f5fbe5b8ed0d82fb818805f06'
4
- data.tar.gz: 7be272e9d21a1d65d0bfe1cbcce921f8492f37af1763fb183e06909f17cb830a
3
+ metadata.gz: 861a45e5f15d787a51c9abde8cf094196eeb903cbb84423a183807a0ab68f2f7
4
+ data.tar.gz: 8776f51765339cbbdc800370a11e0d689efa35bb9f6c9ed9533ab722bad962fc
5
5
  SHA512:
6
- metadata.gz: 3e57ef81615d661a25d12e0503fd77b5622cdf2f78c837835aefdb6e26a261882b29b4b8c6226c1ede13561680986064a91dbe3ccb18c4df895ab30d5448acf0
7
- data.tar.gz: a67756c55f8c52ff1f90279da7ed9dc156f5dbba676c5139b7c951aa5dde01a77c61fc576f85fa60ad8be24658e405d162105cc98f4a0a5dfff89c9ca47f8167
6
+ metadata.gz: 194965a1c5e47f505134a2baba4d1c513ecaa5d4357a22da5ca1a071b98a2a6cc303aafa9dba58944d5c2057cb8bb38d45e2e5fa2033adbc43c99174b8e915f6
7
+ data.tar.gz: d87196c44fd909bf9d88eff7d6b21f9808a56d09d586fc8fd9ab4a3edabf59142046151872e09d2976eb7a10808b88e48de674016068ac7c0696a66638e61900
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ demo*
21
21
  /html
22
22
  spec/fixtures/apps/franky/dynamodb/migrate
23
23
  Gemfile.lock
24
+ .byebug_history
@@ -3,6 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [1.8.8]
7
+ - #206 cache aws service clients globally for lambda performance
8
+ - #211 Jets controller rescue_from support http://rubyonjets.com/docs/rescue-from/
9
+ - #212 fix s3 event function for long bucket names
10
+
6
11
  ## [1.8.7]
7
12
  - #204 from CodingAnarchy/boot-missing-env
8
13
  - #205 rename to rule_event
@@ -10,59 +10,60 @@ require "aws-sdk-sns"
10
10
  require "aws-sdk-sqs"
11
11
 
12
12
  module Jets::AwsServices
13
- autoload :StackStatus, 'jets/aws_services/stack_status'
13
+ autoload :GlobalMemoist, 'jets/aws_services/global_memoist'
14
14
  autoload :S3Bucket, 'jets/aws_services/s3_bucket'
15
+ autoload :StackStatus, 'jets/aws_services/stack_status'
15
16
 
17
+ include GlobalMemoist
16
18
  include StackStatus
17
- extend Memoist
18
19
 
19
20
  def apigateway
20
21
  Aws::APIGateway::Client.new
21
22
  end
22
- memoize :apigateway
23
+ global_memoize :apigateway
23
24
 
24
25
  def cfn
25
26
  Aws::CloudFormation::Client.new
26
27
  end
27
- memoize :cfn
28
+ global_memoize :cfn
28
29
 
29
30
  def dynamodb
30
31
  Aws::DynamoDB::Client.new
31
32
  end
32
- memoize :dynamodb
33
+ global_memoize :dynamodb
33
34
 
34
35
  def lambda
35
36
  Aws::Lambda::Client.new
36
37
  end
37
- memoize :lambda
38
+ global_memoize :lambda
38
39
 
39
40
  def logs
40
41
  Aws::CloudWatchLogs::Client.new
41
42
  end
42
- memoize :logs
43
+ global_memoize :logs
43
44
 
44
45
  def s3
45
46
  Aws::S3::Client.new
46
47
  end
47
- memoize :s3
48
+ global_memoize :s3
48
49
 
49
50
  def s3_resource
50
51
  Aws::S3::Resource.new
51
52
  end
52
- memoize :s3_resource
53
+ global_memoize :s3_resource
53
54
 
54
55
  def sns
55
56
  Aws::SNS::Client.new
56
57
  end
57
- memoize :sns
58
+ global_memoize :sns
58
59
 
59
60
  def sqs
60
61
  Aws::SQS::Client.new
61
62
  end
62
- memoize :sqs
63
+ global_memoize :sqs
63
64
 
64
65
  def sts
65
66
  Aws::STS::Client.new
66
67
  end
67
- memoize :sts
68
+ global_memoize :sts
68
69
  end
@@ -0,0 +1,57 @@
1
+ # We cache the clients globally to avoid re-instantiating them again after the initial Lambda cold start.
2
+ #
3
+ # Based on: https://hashrocket.com/blog/posts/implementing-a-macro-in-ruby-for-memoization
4
+ # Except we use a global variable for the cache. So we'll use the same client across
5
+ # all instances as well as across Lambda executions after the cold-start. Example:
6
+ #
7
+ # class Foo
8
+ # def s3
9
+ # Aws::S3::Client.new
10
+ # end
11
+ # global_memoize :s3
12
+ # end
13
+ #
14
+ # foo1 = Foo.new
15
+ # foo2 = Foo.new
16
+ # foo1.s3
17
+ # foo2.s3 # same client as foo1
18
+ #
19
+ # A prewarmed request after a cold-start will still use the same s3 client instance since it uses the
20
+ # global variable $__memo_methods as the cache.
21
+ #
22
+ module Jets::AwsServices
23
+ module GlobalMemoist
24
+ def self.included(klass)
25
+ klass.extend(Macros)
26
+ end
27
+
28
+ module Macros
29
+ def global_memoize(*methods)
30
+ const_defined?(:"GlobalMemoist#{self.object_id}") ?
31
+ const_get(:"GlobalMemoist#{self.object_id}") : const_set(:"GlobalMemoist#{self.object_id}", Module.new)
32
+ mod = const_get(:"GlobalMemoist#{self.object_id}")
33
+
34
+ mod.class_eval do
35
+ methods.each do |method|
36
+ define_method(method) do |skip_cache = false|
37
+ $__memo_methods ||= {}
38
+ if $__memo_methods.include?(method) && !skip_cache
39
+ $__memo_methods[method]
40
+ else
41
+ $__memo_methods[method] = super()
42
+ end
43
+ end
44
+ end
45
+ end
46
+ prepend mod
47
+ end
48
+
49
+ def global_memoize_class_method(*methods)
50
+ singleton_class.class_eval do
51
+ include GlobalMemoist
52
+ global_memoize(*methods)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -9,6 +9,7 @@ class Jets::Controller
9
9
  include Layout
10
10
  include Params
11
11
  include Rendering
12
+ include ActiveSupport::Rescuable
12
13
 
13
14
  delegate :headers, to: :request
14
15
  delegate :set_header, to: :response
@@ -37,19 +38,24 @@ class Jets::Controller
37
38
  t1 = Time.now
38
39
  log_info_start
39
40
 
40
- if run_before_actions(break_if: -> { @rendered })
41
- send(@meth)
41
+ begin
42
+ if run_before_actions(break_if: -> { @rendered })
43
+ send(@meth)
44
+ action_completed = true
45
+ else
46
+ Jets.logger.info "Filter chain halted as #{@last_callback_name} rendered or redirected"
47
+ end
48
+
42
49
  triplet = ensure_render
43
- run_after_actions
44
- else
45
- Jets.logger.info "Filter chain halted as #{@last_callback_name} rendered or redirected"
50
+ run_after_actions if action_completed
51
+ rescue Exception => exception
52
+ rescue_with_handler(exception) || raise
46
53
  triplet = ensure_render
47
54
  end
48
55
 
49
56
  took = Time.now - t1
50
57
  status = triplet[0]
51
58
  Jets.logger.info "Completed Status Code #{status} in #{took}s"
52
-
53
59
  triplet # status, headers, body
54
60
  end
55
61
 
@@ -4,10 +4,8 @@ class Jets::Controller
4
4
  module Callbacks
5
5
  extend ActiveSupport::Concern
6
6
  included do
7
- class_attribute :before_actions
8
- self.before_actions = []
9
- class_attribute :after_actions
10
- self.after_actions = []
7
+ class_attribute :before_actions, default: []
8
+ class_attribute :after_actions, default: []
11
9
 
12
10
  class << self
13
11
  def before_action(meth, options={})
@@ -38,7 +38,7 @@ module Jets::Stack::Main::Dsl
38
38
  }
39
39
 
40
40
  function_name = "#{Jets.config.project_namespace}-#{class_namespace}-#{meth}"
41
- function_name.size > MAX_FUNCTION_NAME_SIZE ? nil : function_name
41
+ function_name = function_name.size > MAX_FUNCTION_NAME_SIZE ? nil : function_name
42
42
  defaults[:function_name] = function_name if function_name
43
43
 
44
44
  props = defaults.merge(props)
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "1.8.7"
2
+ VERSION = "1.8.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7
4
+ version: 1.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-19 00:00:00.000000000 Z
11
+ date: 2019-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -494,6 +494,7 @@ files:
494
494
  - lib/jets/application.rb
495
495
  - lib/jets/aws_info.rb
496
496
  - lib/jets/aws_services.rb
497
+ - lib/jets/aws_services/global_memoist.rb
497
498
  - lib/jets/aws_services/s3_bucket.rb
498
499
  - lib/jets/aws_services/stack_status.rb
499
500
  - lib/jets/booter.rb