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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73943a13acb609f4322b896b560c2e05a0370cf8b4d710c0977ca7f31e68b8a4
4
- data.tar.gz: 6acee35937485416e6fba60e1e0de2f99185f33763e6e7f63eb6c7b2e34801a5
3
+ metadata.gz: 9341e7c492f4f53e71017855482da53874b08689174ec59a8dba70282fa6ef8e
4
+ data.tar.gz: d302d5891c20027b667ad14a278668ae3cbd0d522a5f0c7ce5b1dd91bd9516ac
5
5
  SHA512:
6
- metadata.gz: ec58b393903efca3cb3b42595671c3baff6074c04adfd0791d59d7a335c143cda434a21d4f647929368d1cb9d25d57cf19b6faef32a05b6f20351dbd7247b427
7
- data.tar.gz: c99e921c14d9633c49cbed484495a64095841752a47bdda9c1810fbee0bfe22d3b72d5231b4b9a29eb6c01f39c417124d92e0eb72c872fea8623b3aa52c4ec74
6
+ metadata.gz: 6dcab4b9b095418a5d4349a378b6f4e457b31394ee9875cba760ea122ee4b2cb3422f396ffdd8d50b547755869b5d07f7dea83947066e5a88eb658e7031c86f4
7
+ data.tar.gz: f57c2df2fe13673fe76d5e19fdcc95b4aa266da1fdf8b14ae91a8466a357c4e3feebe42d39eb1163f5f2a4f92f266ffc840ac01ea1b0864b9d2af45ee349b69e
@@ -1,3 +1,3 @@
1
1
  module Mtracker
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
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
- put_track_info "#{indent}[start#{pid_and_tid}] #{label}"
13
+ start_msg = "#{indent}[start#{pid_and_tid}] #{label}"
14
+ put_track_info start_msg, slack
15
+
12
16
  result = yield
13
- put_track_info "#{indent}[end #{pid_and_tid}] #{label} (#{sprintf('%.3f', Time.now - start_time)} sec)"
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.0
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-04-21 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler