mtracker 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mtracker/version.rb +1 -1
- data/lib/mtracker.rb +21 -5
- 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: 9341e7c492f4f53e71017855482da53874b08689174ec59a8dba70282fa6ef8e
|
4
|
+
data.tar.gz: d302d5891c20027b667ad14a278668ae3cbd0d522a5f0c7ce5b1dd91bd9516ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dcab4b9b095418a5d4349a378b6f4e457b31394ee9875cba760ea122ee4b2cb3422f396ffdd8d50b547755869b5d07f7dea83947066e5a88eb658e7031c86f4
|
7
|
+
data.tar.gz: f57c2df2fe13673fe76d5e19fdcc95b4aa266da1fdf8b14ae91a8466a357c4e3feebe42d39eb1163f5f2a4f92f266ffc840ac01ea1b0864b9d2af45ee349b69e
|
data/lib/mtracker/version.rb
CHANGED
data/lib/mtracker.rb
CHANGED
@@ -2,15 +2,21 @@ require 'mtracker/version'
|
|
2
2
|
|
3
3
|
# module for tracking time
|
4
4
|
module Mtracker
|
5
|
-
attr_accessor :mtracker_log_pid_and_tid
|
5
|
+
attr_accessor :mtracker_log_pid_and_tid, :mtracker_slack_url
|
6
|
+
|
7
|
+
def track(label, options = {})
|
8
|
+
slack = options[:slack]
|
6
9
|
|
7
|
-
def track(label)
|
8
10
|
start_time = Time.now
|
9
11
|
increment_nest_level
|
10
12
|
|
11
|
-
|
13
|
+
start_msg = "#{indent}[start#{pid_and_tid}] #{label}"
|
14
|
+
put_track_info start_msg, slack
|
15
|
+
|
12
16
|
result = yield
|
13
|
-
|
17
|
+
|
18
|
+
finish_msg = "#{indent}[end #{pid_and_tid}] #{label} (#{sprintf('%.3f', Time.now - start_time)} sec)"
|
19
|
+
put_track_info finish_msg, slack
|
14
20
|
|
15
21
|
decrement_nest_level
|
16
22
|
result
|
@@ -47,7 +53,7 @@ module Mtracker
|
|
47
53
|
@mtracker_nest_levels[nest_level_key] = @mtracker_nest_levels[nest_level_key] ? @mtracker_nest_levels[nest_level_key] - 1 : 0
|
48
54
|
end
|
49
55
|
|
50
|
-
def put_track_info(msg)
|
56
|
+
def put_track_info(msg, slack = false)
|
51
57
|
if respond_to?(:logger)
|
52
58
|
logger.info(msg)
|
53
59
|
elsif Rails
|
@@ -55,5 +61,15 @@ module Mtracker
|
|
55
61
|
else
|
56
62
|
puts msg
|
57
63
|
end
|
64
|
+
|
65
|
+
send_to_slack(msg) if slack
|
66
|
+
end
|
67
|
+
|
68
|
+
def send_to_slack(msg)
|
69
|
+
return unless mtracker_slack_url
|
70
|
+
|
71
|
+
uri = URI.parse(mtracker_slack_url)
|
72
|
+
data = { text: msg }
|
73
|
+
Net::HTTP.post_form(uri, payload: data.to_json)
|
58
74
|
end
|
59
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mtracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke Murata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|