jets-rails 0.3.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/CHANGELOG.md +24 -0
- data/{MIT-LICENSE → LICENSE.txt} +3 -1
- data/README.md +8 -11
- data/Rakefile +5 -24
- data/lib/active_job/queue_adapters/jets_job_adapter.rb +13 -0
- data/lib/jets/rails/autoloader.rb +25 -0
- data/lib/jets/rails/engine.rb +28 -0
- data/lib/jets/rails/job/executer.rb +15 -0
- data/lib/jets/rails/job/queue/check.rb +32 -0
- data/lib/jets/rails/job/queue/url.rb +18 -0
- data/lib/jets/rails/job/queue.rb +78 -0
- data/lib/jets/rails/version.rb +7 -0
- data/lib/jets/rails.rb +18 -0
- data/lib/jets-rails.rb +1 -1
- metadata +98 -27
- data/lib/jets_rails/core_ext/kernel.rb +0 -35
- data/lib/jets_rails/logger.rb +0 -14
- data/lib/jets_rails/railtie.rb +0 -7
- data/lib/jets_rails/stage_middleware.rb +0 -26
- data/lib/jets_rails/version.rb +0 -3
- data/lib/jets_rails.rb +0 -24
- data/lib/tasks/jets_rails_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e595a6d2bcfedd7df51acc421676bc6a8d9c2a494d1606eeb02671e39b8bb3df
|
4
|
+
data.tar.gz: dbedc40aefc61125bab3736908566c43162713f6f7fb63cd90eb2f25a795cebb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36daa9d1fb5430db631e4a7c4d2b6293fa60cf45baeaa882b284a3b077671caef0a176f3d4e955cfcbcbeeb126274a4c2b0baf9900b5dabe724afebc6da56e41
|
7
|
+
data.tar.gz: 3f9f6f6aecc4616299db41f8d80bbb0db0ab77b0ddb7cd9efe9a54a91e7bb9a31490717036067a3a4c91f59ab63313cf05343f3294d996d7afb4f850e41945cf
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
## [1.0.1] - 2024-05-21
|
7
|
+
- [#11](https://github.com/rubyonjets/jets-rails/pull/11) reduce rails requirement to => 6.1
|
8
|
+
- rm and gitignore Gemfile.lock
|
9
|
+
|
10
|
+
## [1.0.0] - 2024-05-20
|
11
|
+
|
12
|
+
* jets 6 plugin: activejob jets_job adapter, engine
|
13
|
+
* activejob support jets_job adapter
|
14
|
+
* autoloader app/extensions and shared/extensions autoload paths
|
15
|
+
* before_configuration jets boot
|
16
|
+
* remove 0.3 code full rewrite
|
17
|
+
|
18
|
+
## [0.3.0] - 2018-10-28
|
19
|
+
|
20
|
+
- allow for rails 4
|
21
|
+
|
22
|
+
## [0.1.0] - 2018-10-27
|
23
|
+
|
24
|
+
- Initial release
|
data/{MIT-LICENSE → LICENSE.txt}
RENAMED
data/README.md
CHANGED
@@ -1,16 +1,13 @@
|
|
1
|
-
# Jets Rails
|
1
|
+
# Jets Rails Support
|
2
2
|
|
3
|
-
|
3
|
+
[![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
This gem is not meant to be used standalone. You can enable it though by adding to your Rails Gemfile and setting the `JETS_MEGA=1` env var.
|
5
|
+
A [Jets Plugin](https://docs.rubyonjets.com/docs/plugins/) for Rails and [Jets](http://rubyonjets.com/).
|
8
6
|
|
9
|
-
##
|
7
|
+
## Usage
|
10
8
|
|
11
|
-
|
9
|
+
Add gem to your Gemfile, bundle, and deploy
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
* [Toronto Serverless Presentation: Jets Framework on AWS Lambda](https://blog.boltops.com/2018/09/25/toronto-serverless-presentation-jets-framework-on-aws-lambda)
|
11
|
+
bundle add "jets-rails"
|
12
|
+
jets init
|
13
|
+
jets deploy
|
data/Rakefile
CHANGED
@@ -1,27 +1,8 @@
|
|
1
|
-
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
require
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
8
5
|
|
9
|
-
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'JetsRails'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.md')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
require 'rake/testtask'
|
20
|
-
|
21
|
-
Rake::TestTask.new(:test) do |t|
|
22
|
-
t.libs << 'test'
|
23
|
-
t.pattern = 'test/**/*_test.rb'
|
24
|
-
t.verbose = false
|
25
|
-
end
|
26
|
-
|
27
|
-
task default: :test
|
8
|
+
task default: :spec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "active_job"
|
2
|
+
|
3
|
+
module ActiveJob::QueueAdapters
|
4
|
+
class JetsJobAdapter
|
5
|
+
def enqueue(job)
|
6
|
+
Jets::Rails::Job::Queue.new(job).enqueue
|
7
|
+
end
|
8
|
+
|
9
|
+
def enqueue_at(job, timestamp)
|
10
|
+
Jets::Rails::Job::Queue.new(job, timestamp).enqueue
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "zeitwerk"
|
2
|
+
|
3
|
+
module Jets
|
4
|
+
module Rails
|
5
|
+
class Autoloader
|
6
|
+
class Inflector < Zeitwerk::Inflector
|
7
|
+
def camelize(basename, _abspath)
|
8
|
+
map = {cli: "CLI", version: "VERSION"}
|
9
|
+
map[basename.to_sym] || super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def setup
|
15
|
+
loader = Zeitwerk::Loader.new
|
16
|
+
loader.inflector = Inflector.new
|
17
|
+
lib = File.expand_path("../..", __dir__) # lib
|
18
|
+
loader.push_dir(lib)
|
19
|
+
loader.ignore("#{lib}/jets-rails.rb")
|
20
|
+
loader.setup
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "rails/engine"
|
2
|
+
|
3
|
+
module Jets::Rails
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
# Need to use before_configuration for dotenv
|
6
|
+
# so env values can be used in config/initializers
|
7
|
+
config.before_configuration do
|
8
|
+
Jets.boot # sets up autoloader
|
9
|
+
end
|
10
|
+
|
11
|
+
# Let Jets handle these autoload paths
|
12
|
+
#
|
13
|
+
# Jets.project.config.all_load_paths example:
|
14
|
+
#
|
15
|
+
# app/events
|
16
|
+
# app/extensions
|
17
|
+
# shared/resources
|
18
|
+
# shared/extensions
|
19
|
+
# app/functions
|
20
|
+
# shared/functions
|
21
|
+
#
|
22
|
+
config.before_initialize do
|
23
|
+
Jets.project.config.all_load_paths.each do |path|
|
24
|
+
Rails.autoloaders.main.ignore(Rails.root.join(path))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Jets::Rails::Job::Queue
|
2
|
+
class Check
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
include Jets::Util::Logging
|
7
|
+
|
8
|
+
@@error_message = "ERROR: Unable to get queue url".color(:red)
|
9
|
+
def exist!
|
10
|
+
job_enable!
|
11
|
+
existance!
|
12
|
+
end
|
13
|
+
|
14
|
+
def existance!
|
15
|
+
return if Url.queue_url
|
16
|
+
|
17
|
+
log.error @@error_message
|
18
|
+
raise Error, "Are you sure you have deployed with Jets.project.config.job.enable = true ?"
|
19
|
+
rescue Jets::Api::Error::NotFound
|
20
|
+
log.error @@error_message
|
21
|
+
raise Error, "It does not look like the stack has successfully deployed. Please deploy first."
|
22
|
+
end
|
23
|
+
|
24
|
+
def job_enable!
|
25
|
+
return if Url.queue_url
|
26
|
+
|
27
|
+
log.error @@error_message
|
28
|
+
raise Error, "Are you sure that config.job.enable = true ?"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Jets::Rails::Job::Queue
|
2
|
+
class Url
|
3
|
+
class << self
|
4
|
+
extend Memoist
|
5
|
+
|
6
|
+
def queue_url
|
7
|
+
# JETS_JOB_QUEUE_URL must be set when on AWS Lambda
|
8
|
+
# to avoid the API call to retrieve the queue_url
|
9
|
+
return ENV["JETS_JOB_QUEUE_URL"] if ENV["JETS_JOB_QUEUE_URL"]
|
10
|
+
# 1. can be nil
|
11
|
+
# 2. can raise NotFound error
|
12
|
+
resp = Jets::Api::Release.retrieve("latest")
|
13
|
+
resp.queue_url
|
14
|
+
end
|
15
|
+
memoize :queue_url
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "aws-sdk-sqs"
|
2
|
+
|
3
|
+
module Jets::Rails::Job
|
4
|
+
class Queue
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
extend Memoist
|
8
|
+
include Jets::Util::Logging
|
9
|
+
delegate :queue_url, to: Url
|
10
|
+
|
11
|
+
attr_reader :job, :timestamp
|
12
|
+
def initialize(job, timestamp = nil)
|
13
|
+
@job = job
|
14
|
+
@timestamp = timestamp
|
15
|
+
end
|
16
|
+
|
17
|
+
def enqueue
|
18
|
+
Check.exist!
|
19
|
+
|
20
|
+
params = {
|
21
|
+
queue_url: queue_url,
|
22
|
+
message_body: JSON.dump(job.serialize)
|
23
|
+
}
|
24
|
+
if fifo?
|
25
|
+
params.merge!(fifo_params)
|
26
|
+
else
|
27
|
+
params.merge!(standard_params)
|
28
|
+
end
|
29
|
+
log.info "Enqueueing job to #{queue_url}"
|
30
|
+
log.debug " with params: #{params.inspect}"
|
31
|
+
sqs.send_message(params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def fifo?
|
35
|
+
queue_url.include?(".fifo")
|
36
|
+
end
|
37
|
+
|
38
|
+
def fifo_params
|
39
|
+
options = {}
|
40
|
+
options[:message_deduplication_id] = message_deduplication_id
|
41
|
+
|
42
|
+
message_group_id = @job.message_group_id if @job.respond_to?(:message_group_id)
|
43
|
+
message_group_id ||= "jets"
|
44
|
+
|
45
|
+
options[:message_group_id] = message_group_id
|
46
|
+
options
|
47
|
+
end
|
48
|
+
|
49
|
+
# Note that `job_id` is NOT included in deduplication keys because it is unique for
|
50
|
+
# each initialization of the job, and the run-once behavior must be guaranteed for ActiveJob retries.
|
51
|
+
# Even without setting job_id, it is implicitly excluded from deduplication keys.
|
52
|
+
def message_deduplication_id
|
53
|
+
ex_dedup_keys = @job.excluded_deduplication_keys if @job.respond_to?(:excluded_deduplication_keys)
|
54
|
+
ex_dedup_keys ||= []
|
55
|
+
ex_dedup_keys += ["job_id"]
|
56
|
+
body = @job.serialize
|
57
|
+
deduplication_body = body.except(*ex_dedup_keys)
|
58
|
+
Digest::SHA256.hexdigest(JSON.dump(deduplication_body))
|
59
|
+
end
|
60
|
+
|
61
|
+
def standard_params
|
62
|
+
@timestamp ? {delay_seconds: delay_seconds} : {}
|
63
|
+
end
|
64
|
+
|
65
|
+
def delay_seconds
|
66
|
+
delay = (@timestamp - Time.now.to_f).floor
|
67
|
+
delay = 0 if delay.negative?
|
68
|
+
raise ArgumentError, "Unable to queue a job with a delay greater than 15 minutes" if delay > 15.minutes
|
69
|
+
|
70
|
+
delay
|
71
|
+
end
|
72
|
+
|
73
|
+
def sqs
|
74
|
+
Aws::SQS::Client.new
|
75
|
+
end
|
76
|
+
memoize :sqs
|
77
|
+
end
|
78
|
+
end
|
data/lib/jets/rails.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$:.unshift(File.expand_path("..", __dir__))
|
4
|
+
require "active_job/queue_adapters/jets_job_adapter"
|
5
|
+
|
6
|
+
require "jets/rails/autoloader"
|
7
|
+
Jets::Rails::Autoloader.setup
|
8
|
+
|
9
|
+
require "memoist"
|
10
|
+
require "rainbow/ext/string"
|
11
|
+
|
12
|
+
module Jets
|
13
|
+
module Rails
|
14
|
+
class Error < StandardError; end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require "jets/rails/engine" if defined?(Rails::Railtie)
|
data/lib/jets-rails.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "jets/rails"
|
metadata
CHANGED
@@ -1,67 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jets-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-sqs
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: memoist
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: rails
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
16
72
|
requirements:
|
17
|
-
- - "
|
73
|
+
- - ">="
|
18
74
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
75
|
+
version: '6.1'
|
20
76
|
type: :runtime
|
21
77
|
prerelease: false
|
22
78
|
version_requirements: !ruby/object:Gem::Requirement
|
23
79
|
requirements:
|
24
|
-
- - "
|
80
|
+
- - ">="
|
25
81
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
82
|
+
version: '6.1'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
84
|
+
name: rainbow
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
30
86
|
requirements:
|
31
87
|
- - ">="
|
32
88
|
- !ruby/object:Gem::Version
|
33
89
|
version: '0'
|
34
|
-
type: :
|
90
|
+
type: :runtime
|
35
91
|
prerelease: false
|
36
92
|
version_requirements: !ruby/object:Gem::Requirement
|
37
93
|
requirements:
|
38
94
|
- - ">="
|
39
95
|
- !ruby/object:Gem::Version
|
40
96
|
version: '0'
|
41
|
-
|
42
|
-
|
43
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: zeitwerk
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
44
112
|
email:
|
45
113
|
- tongueroo@gmail.com
|
46
114
|
executables: []
|
47
115
|
extensions: []
|
48
116
|
extra_rdoc_files: []
|
49
117
|
files:
|
50
|
-
-
|
118
|
+
- ".rspec"
|
119
|
+
- CHANGELOG.md
|
120
|
+
- LICENSE.txt
|
51
121
|
- README.md
|
52
122
|
- Rakefile
|
123
|
+
- lib/active_job/queue_adapters/jets_job_adapter.rb
|
53
124
|
- lib/jets-rails.rb
|
54
|
-
- lib/
|
55
|
-
- lib/
|
56
|
-
- lib/
|
57
|
-
- lib/
|
58
|
-
- lib/
|
59
|
-
- lib/
|
60
|
-
- lib/
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
metadata:
|
125
|
+
- lib/jets/rails.rb
|
126
|
+
- lib/jets/rails/autoloader.rb
|
127
|
+
- lib/jets/rails/engine.rb
|
128
|
+
- lib/jets/rails/job/executer.rb
|
129
|
+
- lib/jets/rails/job/queue.rb
|
130
|
+
- lib/jets/rails/job/queue/check.rb
|
131
|
+
- lib/jets/rails/job/queue/url.rb
|
132
|
+
- lib/jets/rails/version.rb
|
133
|
+
homepage: https://github.com/rubyonjets/jets-rails
|
134
|
+
licenses: []
|
135
|
+
metadata:
|
136
|
+
homepage_uri: https://github.com/rubyonjets/jets-rails
|
65
137
|
post_install_message:
|
66
138
|
rdoc_options: []
|
67
139
|
require_paths:
|
@@ -70,16 +142,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
142
|
requirements:
|
71
143
|
- - ">="
|
72
144
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
145
|
+
version: 3.2.0
|
74
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
147
|
requirements:
|
76
148
|
- - ">="
|
77
149
|
- !ruby/object:Gem::Version
|
78
150
|
version: '0'
|
79
151
|
requirements: []
|
80
|
-
|
81
|
-
rubygems_version: 2.7.6
|
152
|
+
rubygems_version: 3.5.10
|
82
153
|
signing_key:
|
83
154
|
specification_version: 4
|
84
|
-
summary: Jets
|
155
|
+
summary: Jets Rails Support
|
85
156
|
test_files: []
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# With this implementation we write to disk immedaitely. This simplifies the
|
2
|
-
# implementation because we do not have to flush to io buffer by passing signals
|
3
|
-
# back and forth from the jets ruby server process to the rack server process.
|
4
|
-
module Kernel
|
5
|
-
# List from https://ruby-doc.org/core-2.5.1/Kernel.html
|
6
|
-
# Note, will lose pp format in the @io_buffer but looks like a lot of work to keep the pp format.
|
7
|
-
# Must override stdout which can be messy quick: https://www.ruby-forum.com/topic/43725
|
8
|
-
OVERRIDE_METHODS = %w[
|
9
|
-
p
|
10
|
-
pp
|
11
|
-
print
|
12
|
-
printf
|
13
|
-
putc
|
14
|
-
puts
|
15
|
-
]
|
16
|
-
# NOTE adding sprintf produces #<%s: %s:%s/%s> with puma? So not including sprintf
|
17
|
-
OVERRIDE_METHODS.each do |meth|
|
18
|
-
# Example of generated code:
|
19
|
-
#
|
20
|
-
# alias_method :original_puts, :puts
|
21
|
-
# def puts(*args, &block)
|
22
|
-
# original_puts(*args, &block)
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
class_eval <<~CODE
|
26
|
-
alias_method :original_#{meth}, :#{meth}
|
27
|
-
def #{meth}(*args, &block)
|
28
|
-
# Write immediately for debugging
|
29
|
-
message = "Rails: " + args.first.to_s + "\n"
|
30
|
-
IO.write("/tmp/jets-output.log", message, mode: 'a')
|
31
|
-
original_#{meth}(*args, &block)
|
32
|
-
end
|
33
|
-
CODE
|
34
|
-
end
|
35
|
-
end
|
data/lib/jets_rails/logger.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
# Tap into rails logging to show logs in CloudWatch eventually.
|
4
|
-
#
|
5
|
-
# Overriding Rails SimpleFormatter directly is pretty simple approach.
|
6
|
-
# The definition is short.
|
7
|
-
class ActiveSupport::Logger::SimpleFormatter
|
8
|
-
# This method is invoked when a log event occurs
|
9
|
-
def call(severity, timestamp, progname, msg)
|
10
|
-
result = "#{String === msg ? msg : msg.inspect}\n"
|
11
|
-
IO.write("/tmp/jets-output.log", "Rails: #{result}", mode: 'a')
|
12
|
-
result
|
13
|
-
end
|
14
|
-
end
|
data/lib/jets_rails/railtie.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module JetsRails
|
2
|
-
class StageMiddleware
|
3
|
-
def initialize(app)
|
4
|
-
@app = app
|
5
|
-
end
|
6
|
-
|
7
|
-
def call(env)
|
8
|
-
add_stage_name(env) if on_aws?(env)
|
9
|
-
status, headers, body = @app.call(env)
|
10
|
-
[status, headers, body]
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
# Add API Gateway Stage Name
|
15
|
-
def add_stage_name(env)
|
16
|
-
# changes links that Rails generates
|
17
|
-
env[Rack::SCRIPT_NAME] = "/#{JetsRails.stage}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def on_aws?(env)
|
21
|
-
return true if ENV['JETS_ON_AWS'] # for local testing
|
22
|
-
host = env['HTTP_X_FORWARDED_HOST'] # from Jets::Rack::Request#set_headers!
|
23
|
-
host&.include?("amazonaws.com")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/jets_rails/version.rb
DELETED
data/lib/jets_rails.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# JETS_MEGA is set in the bin/rackup wrapper
|
2
|
-
# We do this check so we can include jets-rails in the Gemfile and allow users
|
3
|
-
# to check to see if the bundle install will work though this is not activated
|
4
|
-
# logically without JETS_MEGA set.
|
5
|
-
return unless ENV['JETS_MEGA']
|
6
|
-
|
7
|
-
# = Configuration
|
8
|
-
#
|
9
|
-
# Configure with Rails initializer. Example:
|
10
|
-
#
|
11
|
-
# config/initializer/jets.rb:
|
12
|
-
#
|
13
|
-
# JetsRails.stage = ENV['JETS_STAGE'] || 'dev'
|
14
|
-
#
|
15
|
-
module JetsRails
|
16
|
-
cattr_accessor :stage
|
17
|
-
self.stage = "dev" # default. should be set to in Rails initializer
|
18
|
-
|
19
|
-
autoload :StageMiddleware, 'jets_rails/stage_middleware'
|
20
|
-
end
|
21
|
-
|
22
|
-
require "jets_rails/core_ext/kernel"
|
23
|
-
require "jets_rails/logger" # eager load rails override
|
24
|
-
require "jets_rails/railtie"
|