jets 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46b439f0c17028d8e6ba1a990fc738e6920e074da8f2d43a08717f55ffc7c32c
4
- data.tar.gz: b9ec45848d7d53db76e9b3e222f01262bfdc11076923508932033a1f6d0e9d42
3
+ metadata.gz: ba1ae625286077b458d497643590d72d83d10e800ce1d8fc1bf18599260501a0
4
+ data.tar.gz: cdccc52793152392901ae9c27e5bfbeafaccf49d4fc78fea70dc28feeda0d8ee
5
5
  SHA512:
6
- metadata.gz: 9c145fc325470e209d0b219a5cd3a77052e6b15b4ba9b4d5e9786ea8b9d05e254f14136565f8e70552449ca82c0c7976a6a5e248165a1aeee63583bab17978cf
7
- data.tar.gz: f78b28c18e767a2d43ad0bb719d6c91eaed94b0b5ac6ffb85fc44d933adbacc38167391512d986ac7b4b6b3b487654cd6d065f3e8f67238d71d880a1c0f63514
6
+ metadata.gz: 6ead8f6f9e01613c614e6815e25ad777413fb2222e07b065962a7ee3e33d19dad7dcb7fd9a158da57543ba9ec65c3634043081ea44636227a633d29dbb914035
7
+ data.tar.gz: 59a7f19c9e3486d68462f929d0ef93b54ec752edc4ae9b880bd535fd57d969370088a4053c4bf37cd0da63ed2b113ffe75b8804e6f7842da182c39a5b6223ace
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.6.6]
7
+ - improve puts handling: PR #15
8
+
6
9
  ## [0.6.5]
7
10
  - fix prewarming after a deploy
8
11
 
data/Gemfile.lock CHANGED
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (0.6.4)
14
+ jets (0.6.6)
15
15
  actionpack (>= 5.2.1)
16
16
  actionview (>= 5.2.1)
17
17
  activerecord (>= 5.2.1)
data/lib/jets.rb CHANGED
@@ -44,13 +44,16 @@ module Jets
44
44
  extend Core # root, logger, etc
45
45
 
46
46
  autoload :RubyServer, "jets/ruby_server"
47
+ autoload :IO, "jets/io"
48
+ autoload :Logger, "jets/logger"
47
49
  end
48
50
 
51
+ require "jets/core_ext/kernel"
52
+
49
53
  $:.unshift(File.expand_path("../../vendor/lambdagem/lib", __FILE__))
50
54
  require "lambdagem"
51
55
  require "gems" # lambdagem dependency
52
56
 
53
-
54
57
  # lazy loaded dependencies: depends what project. Mainly determined by Gemfile
55
58
  # and config files.
56
59
  if File.exist?("#{Jets.root}config/dynamodb.yml")
data/lib/jets/booter.rb CHANGED
@@ -4,7 +4,7 @@ class Jets::Booter
4
4
  def boot!(options={})
5
5
  return if @booted
6
6
 
7
- redirect_output(options)
7
+ redirect_output
8
8
  confirm_jets_project!
9
9
  require_bundle_gems
10
10
  Jets::Dotenv.load!
@@ -14,37 +14,21 @@ class Jets::Booter
14
14
  @booted = true
15
15
  end
16
16
 
17
- # TODO: Reconsider if we should redirect stdout to stderr globally for local request.
18
- # Dont think we need to anymore now that we're not using the old shim.
17
+ # AWS Lambda for natively supported languages prints to CloudWatch instead of
18
+ # mungling up the response. We'll redirect stdout to stderr to mimic AWS Lambda
19
+ # behavior.
19
20
  #
20
- # So for `{stringio: false}` and `jets call --local`, redirecting helps
21
- # but we can also just go fix that jets call method. Though there might be a lot
22
- # of other places where we might have to fix puts calls.
23
- def redirect_output(options={})
21
+ # Also, for local use, printing to stdout can mangle up the response when piping
22
+ # the value to jq. For example:
23
+ #
24
+ # `jets call --local .. | jq`
25
+ #
26
+ # By redirecting stderr we can use jq safely.
27
+ #
28
+ def redirect_output
24
29
  $stdout.sync = true
25
30
  $stderr.sync = true
26
- if options[:stringio]
27
- # Set both $stdout and $stdout to a StringIO object as a buffer.
28
- # At the end of the request, write this buffer to the filesystem.
29
- # In the node shim, read it back and write it to AWS Lambda logs.
30
- #
31
- # This allows using `puts` to write to CloudWatch.
32
- $stdout = $stderr = StringIO.new # for ruby_server and AWS Lambda to capture log
33
- else
34
- # Printing to stdout can mangle up the response if we're piping the value to
35
- # jq. For exampe, `jets call --local .. | jq`
36
- # By redirecting stderr we can use jq.
37
- #
38
- $stdout = $stderr # jets call and local jets operation
39
- end
40
- end
41
-
42
- # Used in ruby_server.rb
43
- def flush_output
44
- IO.write("/tmp/jets-output.log", $stdout.string)
45
- # Thanks: https://stackoverflow.com/questions/28445000/how-can-i-clear-a-stringio-instance
46
- $stdout.truncate(0)
47
- $stdout.rewind
31
+ $stdout = $stderr # jets call and local jets operation
48
32
  end
49
33
 
50
34
  # require_bundle_gems called when environment boots up via Jets.boot. It
@@ -12,6 +12,7 @@ module Jets::Commands
12
12
  puts "Deploying to Lambda #{deployment_env} environment..."
13
13
  return if @options[:noop]
14
14
 
15
+ check_dev_mode
15
16
  build_code
16
17
  validate_routes!
17
18
 
@@ -24,6 +25,13 @@ module Jets::Commands
24
25
  end
25
26
  time :run
26
27
 
28
+ def check_dev_mode
29
+ if File.exist?("#{Jets.root}dev.mode")
30
+ puts "The dev.mode file exists. Please removed it and run bundle update before you deploy.".colorize(:red)
31
+ exit 1
32
+ end
33
+ end
34
+
27
35
  def build_code
28
36
  Jets::Commands::Build.new(@options).build_code
29
37
  end
data/lib/jets/core.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'logger'
2
1
  require 'active_support/dependencies'
3
2
  require 'memoist'
4
3
 
@@ -65,7 +64,7 @@ module Jets::Core
65
64
  memoize :build_root
66
65
 
67
66
  def logger
68
- Logger.new($stderr)
67
+ Jets::Logger.new($stderr)
69
68
  end
70
69
  memoize :logger
71
70
 
@@ -0,0 +1,23 @@
1
+ # Works with jets/io.rb
2
+ module Kernel
3
+ @@io_buffer = []
4
+
5
+ alias_method :original_puts, :puts
6
+ def puts(message)
7
+ @@io_buffer << message
8
+ original_puts(message)
9
+ end
10
+
11
+ # TODO: implement other methods that write output:
12
+ # p, print, printf, putc, puts, sprintf?
13
+ # Also, would be nice to figure out pp method also.
14
+
15
+ def io_buffer
16
+ @@io_buffer
17
+ end
18
+
19
+ def io_flush
20
+ IO.write("/tmp/jets-output.log", @@io_buffer.join("\n"))
21
+ @@io_buffer = []
22
+ end
23
+ end
data/lib/jets/io.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Wrapper class works with jets/core_ext/kernel.rb
2
+ module Jets
3
+ class IO
4
+ class << self
5
+ def buffer
6
+ Kernel.io_buffer
7
+ end
8
+
9
+ def flush
10
+ Kernel.io_flush
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ require 'logger'
2
+
3
+ module Jets
4
+ class Logger < ::Logger
5
+ # Only need to override the add method as the other calls all lead to it.
6
+ def add(severity, message = nil, progname = nil)
7
+ # Taken from Logger#add source
8
+ # https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html#method-i-add
9
+ if message.nil?
10
+ if block_given?
11
+ message = yield
12
+ else
13
+ message = progname
14
+ progname = @progname
15
+ end
16
+ end
17
+ # Put the message in the Jets::IO.buffer which will get flushed to CloudWatch.
18
+ # No need to include timestamp as CloudWatch already has a timestamp.
19
+ IO.buffer << message
20
+
21
+ super # original logical
22
+ end
23
+ end
24
+ end
@@ -66,7 +66,7 @@ module Jets
66
66
  prewarm_request(event) :
67
67
  standard_request(event, '{}', handler)
68
68
 
69
- Jets::Booter.flush_output # flushing output as soon we dont need it anymore
69
+ Jets::IO.flush # flush output and write to disk for node shim
70
70
 
71
71
  client.puts(result)
72
72
  client.close
@@ -76,6 +76,7 @@ module Jets
76
76
  def prewarm_request(event)
77
77
  # JSON.dump("prewarmed_at" => Time.now.to_s)
78
78
  Jets.increase_prewarm_count
79
+ Jets.logger.info("Prewarm request")
79
80
  %Q|{"prewarmed_at":"#{Time.now.to_s}"}| # raw json for speed
80
81
  end
81
82
 
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
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: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -548,6 +548,7 @@ files:
548
548
  - lib/jets/controller/rendering.rb
549
549
  - lib/jets/controller/request.rb
550
550
  - lib/jets/core.rb
551
+ - lib/jets/core_ext/kernel.rb
551
552
  - lib/jets/default/application.rb
552
553
  - lib/jets/dotenv.rb
553
554
  - lib/jets/erb.rb
@@ -571,6 +572,7 @@ files:
571
572
  - lib/jets/internal/app/controllers/jets/welcome_controller.rb
572
573
  - lib/jets/internal/app/controllers/jets/welcome_controller/python/index.py
573
574
  - lib/jets/internal/app/jobs/jets/preheat_job.rb
575
+ - lib/jets/io.rb
574
576
  - lib/jets/job.rb
575
577
  - lib/jets/job/base.rb
576
578
  - lib/jets/job/dsl.rb
@@ -582,6 +584,7 @@ files:
582
584
  - lib/jets/lambda/function_constructor.rb
583
585
  - lib/jets/lambda/functions.rb
584
586
  - lib/jets/lambda/task.rb
587
+ - lib/jets/logger.rb
585
588
  - lib/jets/naming.rb
586
589
  - lib/jets/pascalize.rb
587
590
  - lib/jets/poly_fun.rb