oyencov 0.0.9 → 0.0.10
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 +4 -4
- data/lib/oyencov/api_connection.rb +1 -1
- data/lib/oyencov/background.rb +16 -2
- data/lib/oyencov/cli.rb +3 -5
- data/lib/oyencov/configuration.rb +1 -1
- data/lib/oyencov/logger.rb +1 -1
- data/lib/oyencov/railtie.rb +8 -4
- data/lib/oyencov/version.rb +1 -1
- data/lib/oyencov.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a4f51c426c0d097999e548f0ba5920105655e1fbb04b731055573889239fb85
|
4
|
+
data.tar.gz: 57eee19f6e39579159c9175ee78faf3b8b7e6e40d8f1adb15fe85d325ee0c652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf0d4fd53946d6fe3e43155a3dd9aa3dca94d81054a8b8b0789e29a3241cb26589f25e565fb0b31e4874ae5ec91f8e69c47defc275a4d2272259f4c8823ec7bf
|
7
|
+
data.tar.gz: 106e34406d36a110d79f21b536c0deaa304ff3ed927b100c7343917b5a6c4dbe0d05c70a400d84e69d2e97d5a7a918e3d1fa712474ca896a506c13d84f35dc45
|
data/lib/oyencov/background.rb
CHANGED
@@ -17,14 +17,24 @@ require_relative "logger"
|
|
17
17
|
#
|
18
18
|
module OyenCov
|
19
19
|
class Background
|
20
|
+
# Added to be more fork-aware. Ruby/Puma can fork a process copy-on-write,
|
21
|
+
# but it won't start the threads that are running in the parent process.
|
22
|
+
#
|
23
|
+
# If the PID > 0 but also not the current process_id, make the thread run.
|
24
|
+
@@running_pid = 0
|
25
|
+
|
20
26
|
@loop_interval = 60 # seconds, can be set from server
|
21
|
-
@semaphore = Mutex.new
|
22
27
|
@thread = nil
|
23
28
|
@reporter = nil
|
24
29
|
@api_conn = OyenCov::APIConnection.instance
|
25
30
|
@config = OyenCov.config
|
26
31
|
|
27
32
|
def self.start
|
33
|
+
if @@running_pid == $$
|
34
|
+
OyenCov::Logger.log("OyenCov Background thread is already running.")
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
28
38
|
OyenCov::Logger.log(<<~TXT)
|
29
39
|
Env: #{@config.mode}
|
30
40
|
program_name: #{$PROGRAM_NAME || "nil"}
|
@@ -45,7 +55,7 @@ module OyenCov
|
|
45
55
|
clearance = @api_conn.get_data_submission_clearance
|
46
56
|
|
47
57
|
unless clearance && clearance["status"] == "ok"
|
48
|
-
OyenCov::Logger.log "Unable to obtain oyencov submission clearance. Stopping OyenCov background thread."
|
58
|
+
OyenCov::Logger.log "Unable to obtain oyencov submission clearance. Stopping OyenCov background thread. #{clearance.inspect}"
|
49
59
|
Thread.stop
|
50
60
|
end
|
51
61
|
|
@@ -79,6 +89,7 @@ module OyenCov
|
|
79
89
|
OyenCov::Logger.log "POST runtime_report ok."
|
80
90
|
else
|
81
91
|
OyenCov::Logger.log "POST runtime_report failed. Stopping background thread."
|
92
|
+
@@running_pid = 0
|
82
93
|
Thread.stop
|
83
94
|
end
|
84
95
|
|
@@ -87,6 +98,8 @@ module OyenCov
|
|
87
98
|
}
|
88
99
|
|
89
100
|
@thread.run
|
101
|
+
OyenCov::Logger.log("OyenCov Background thread starts.")
|
102
|
+
@@running_pid = $$
|
90
103
|
|
91
104
|
nil
|
92
105
|
end
|
@@ -95,6 +108,7 @@ module OyenCov
|
|
95
108
|
# For `test`, persist controller report.
|
96
109
|
def self.stop
|
97
110
|
@thread.stop
|
111
|
+
@@running_pid = 0
|
98
112
|
end
|
99
113
|
|
100
114
|
private_class_method
|
data/lib/oyencov/cli.rb
CHANGED
@@ -82,11 +82,9 @@ module OyenCov
|
|
82
82
|
"git_commit_sha" => options[:git_commit_sha]
|
83
83
|
})
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
ENV["OYENCOV_API_KEY"] ||= options[:token]
|
85
|
+
if options[:token]
|
86
|
+
ENV["OYENCOV_API_KEY"] = options[:token]
|
87
|
+
end
|
90
88
|
unless ENV["OYENCOV_API_KEY"]
|
91
89
|
warn "API token not set. Unable to submit."
|
92
90
|
exit(1)
|
@@ -42,7 +42,7 @@ module OyenCov
|
|
42
42
|
|
43
43
|
# Lots of ideas came from sentry-ruby, thanks to nate berkopec.
|
44
44
|
def suggest_release
|
45
|
-
release = `git rev-parse HEAD
|
45
|
+
release = `git rev-parse HEAD 2>/dev/null || true`.strip
|
46
46
|
|
47
47
|
if release == "" || release.nil?
|
48
48
|
[".source_version", "REVISION"].each do |version_clue|
|
data/lib/oyencov/logger.rb
CHANGED
@@ -12,7 +12,7 @@ module OyenCov
|
|
12
12
|
if Exception === msg
|
13
13
|
msg = msg.inspect
|
14
14
|
end
|
15
|
-
formatted_msg = msg.split("\n").map { |m| "#{ORANGE_TEXT}[OyenCov] #{m}#{RESET_COLOR}" }.join("\n")
|
15
|
+
formatted_msg = msg.split("\n").map { |m| "#{ORANGE_TEXT}[OyenCov] PID##{$$} #{m}#{RESET_COLOR}" }.join("\n")
|
16
16
|
|
17
17
|
if level == 2
|
18
18
|
warn formatted_msg
|
data/lib/oyencov/railtie.rb
CHANGED
@@ -5,6 +5,8 @@ require_relative "logger"
|
|
5
5
|
|
6
6
|
module OyenCov
|
7
7
|
class Railtie < Rails::Railtie
|
8
|
+
@@controller_tracker_notification = nil
|
9
|
+
|
8
10
|
# This is only useful when `rails s` is run in lieu of webserver command first.
|
9
11
|
def install_puma_hooks
|
10
12
|
return unless defined?(Puma)
|
@@ -26,12 +28,14 @@ module OyenCov
|
|
26
28
|
initializer "oyencov.configure" do
|
27
29
|
OyenCov::Background.start
|
28
30
|
install_puma_hooks
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
if @@controller_tracker_notification.nil?
|
33
|
+
OyenCov::Logger.log "@@controller_tracker_notification is nil"
|
34
|
+
else
|
35
|
+
OyenCov::Logger.log "@@controller_tracker_notification is already set, Railtie init rerun."
|
36
|
+
end
|
33
37
|
|
34
|
-
ActiveSupport::Notifications.subscribe("start_processing.action_controller") do |name, start, finish, id, payload|
|
38
|
+
@@controller_tracker_notification ||= ActiveSupport::Notifications.subscribe("start_processing.action_controller") do |name, start, finish, id, payload|
|
35
39
|
ControllerTracking.bump("#{payload[:controller]}##{payload[:action]}")
|
36
40
|
OyenCov::Logger.log "ControllerTracking.bump(#{payload[:controller]}##{payload[:action]})"
|
37
41
|
end
|
data/lib/oyencov/version.rb
CHANGED
data/lib/oyencov.rb
CHANGED
@@ -11,14 +11,20 @@ module OyenCov
|
|
11
11
|
|
12
12
|
# Sometimes oyencov cant start on their own, maybe when oyencov is loaded
|
13
13
|
# before Rails did.
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# For Rails, put `OyenCov.start!` in `config/initializers/oyencov.rb`.
|
16
16
|
def self.start!
|
17
17
|
require_relative "oyencov/railtie"
|
18
18
|
end
|
19
19
|
|
20
20
|
OyenCov::Logger.log("Hello! Booting from #{__FILE__}")
|
21
|
-
OyenCov::Logger.log("Checking Rails existence")
|
21
|
+
OyenCov::Logger.log("Checking/Forcing Rails existence")
|
22
|
+
|
23
|
+
begin
|
24
|
+
require "rails"
|
25
|
+
rescue LoadError
|
26
|
+
# do nothing
|
27
|
+
end
|
22
28
|
|
23
29
|
if defined?(Rails::Railtie) # && ENV["OYENCOV_API_KEY"]
|
24
30
|
OyenCov::Logger.log("Rails::Railtie already present, starting oyencov/railtie")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oyencov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anonoz Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|