step-track 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 44d2a673a0a4ad99bef64eb7c0b6938f87a30ede
4
- data.tar.gz: 42f58e8beae25271da55980d72e4d1d35fb243dc
3
+ metadata.gz: 1e7fbc29e0c6322fafba55a9cbbdc62edc015b30
4
+ data.tar.gz: 59a755c0ad211f30927ac47e1ccd4e00d704b279
5
5
  SHA512:
6
- metadata.gz: 67becd249f79ffd6e4ccf073190fa6b83a14b2e78b7d256e0fd19f254173629d5a1bc575946c2bbd85d665d664e94b5bca8edf91d4cc2d820e590940effbb833
7
- data.tar.gz: b2d198521e9ada64b4a5b5159757b424b60143dcc5cb836b329dcb80b6a56ea63b7f04904573526e3c4f238c9e0a576dcd423417d9361b48689d442dd7f10036
6
+ metadata.gz: d9eaa71b6e0018cefd9631b9df58ae5c90f145db490e15539308d26a56ee9aab7807bd97e420c75296da06f0891a06543186eb1bdfb31776ab739389d03d8240
7
+ data.tar.gz: 2dcc4bc50959135f4656c455228bba454132abb65c69ddf8a767df24515a9445cdd673e8b1d9b1b1cae482671c123ce03133ecafff0429dd7944f18b8f068e23
data/lib/step_track.rb CHANGED
@@ -5,26 +5,28 @@ module StepTrack
5
5
 
6
6
  REF = "step_track/%{track}"
7
7
 
8
- def init(track)
8
+ def init(track, config={merge_key: :merge, error_key: :error})
9
9
  raise ArgumentError, "callback block required" unless block_given?
10
10
  Thread.current[ref(track)] = {
11
11
  steps: [],
12
12
  callback: Proc.new,
13
13
  time: Time.now
14
- }
14
+ }.merge(config)
15
15
  end
16
16
 
17
17
  def push(track, name, payload={})
18
18
  require_init!(track)
19
19
  track_ref = Thread.current[ref(track)]
20
+ return if track_ref[:steps].last&.[](track_ref[:error_key])
21
+ merge_step = track_ref[:steps].pop if payload.delete(track_ref[:merge_key])
20
22
  last_step = track_ref[:steps].last
21
- track_ref[:steps] << {
22
- split: Time.now - (last_step&.[](:time) || track_ref[:time]),
23
- duration: Time.now - track_ref[:time],
23
+ track_ref[:steps] << (merge_step || {}).merge(
24
+ split: Time.now.to_f - (last_step&.[](:time) || track_ref[:time]).to_f,
25
+ duration: Time.now.to_f - track_ref[:time].to_f,
24
26
  time: Time.now,
25
27
  caller: caller[0].sub(Dir.pwd + "/", ""),
26
28
  name: name
27
- }.merge(payload)
29
+ ).merge(payload)
28
30
  end
29
31
 
30
32
  def done(track)
@@ -37,6 +39,7 @@ module StepTrack
37
39
  result.merge!(steps.last || {})
38
40
  steps.each_with_index do |step, i|
39
41
  name = step[:name]
42
+ [:split, :duration].each { |k| step[k] = (step[k] * 1000).to_i }
40
43
  result.merge!(step.merge(i: i + 1).
41
44
  map { |k, v| ["step_#{name}_#{k}".to_sym, v] }.to_h)
42
45
  end
@@ -1,3 +1,3 @@
1
1
  module StepTrack
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -51,6 +51,24 @@ describe "StepTrack" do
51
51
  expected_keys = [:name, :split, :duration, :time, :caller]
52
52
  assert_equal expected_keys, expected_keys & step.keys
53
53
  end
54
+
55
+ it "does nothing when previous step was an error" do
56
+ StepTrack.push("test", "step", moo: "bar", error: true)
57
+ data = Thread.current[StepTrack.send(:ref, "test")]
58
+ assert_equal 1, data[:steps].size
59
+ StepTrack.push("test", "new")
60
+ assert_equal 1, data[:steps].size
61
+ end
62
+
63
+ it "merges the new payload into the previous result when requested" do
64
+ StepTrack.push("test", "step", moo: "bar")
65
+ StepTrack.push("test", "new", blu: "gnu", merge: true)
66
+ data = Thread.current[StepTrack.send(:ref, "test")]
67
+ assert_equal 1, data[:steps].size
68
+ step = data[:steps].first
69
+ assert_equal "bar", step[:moo]
70
+ assert_equal "gnu", step[:blu]
71
+ end
54
72
  end
55
73
 
56
74
  describe ".done" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: step-track
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Geier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest