lowloop 0.8.16 → 0.8.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53d6cf9b4dc4c2d7da0fafc75ea0a012f9c665de1a9707fc4f5cd0a6819eb0e2
4
- data.tar.gz: 242c11146c4d2b3eda2f201a3181aa6b07bd0e683612eeb687e3d018236f76e9
3
+ metadata.gz: a1222163a4798e1a2508a0a049a3345d49ecac4693b2d4a326afea93bc0ca103
4
+ data.tar.gz: cf9372d768bf6ed5f025a7fb3a15e8e74f89b2d54c2c91e226572b59a12251de
5
5
  SHA512:
6
- metadata.gz: 80f3afccac6eef15e81c970681f09e147fbca0344f52decdc362bed8b69590fcf4e54e4ff34691742f6d5def18680cfb2c7f101795cb63677cc0277c64074406
7
- data.tar.gz: 71349ca0269cb29052e40b077e6edd930d64f503c1ee7256e65878e2a830cb2b5977ac8f98baada742b117467bac93db8892f153c0bbd9bc8f4137104ed9a43b
6
+ metadata.gz: 308c54b96ada7d81d2db9725dd3974e8a7c68297b76c4e48b9b3cc4361031995e517ca56e9045f421f8dc96b13a9653f381893eebf71aa4db2fc66a3e8f258ad
7
+ data.tar.gz: a0fa638b481431f9742577698659ef1854905c8dda44f306de51986805657855ba1e051f64970b2080696e5e7d2506d763632a0de8fea55cfb0bdb22aa66b3b1
@@ -13,6 +13,8 @@ module Low
13
13
  # Interval[every_minute: 3, at_hour: 2]
14
14
  class Interval < Low::Event
15
15
  UNITS = { every_second: 1, every_minute: 60, every_hour: 3600, every_day: 86_400 }.freeze
16
+ # Enough recent turns' outcomes for a dial of up to 60 marks like each second of a minute.
17
+ KEPT_OUTCOMES = 64
16
18
 
17
19
  attr_reader :seconds, :at_hour, :triggered_at
18
20
 
@@ -37,6 +39,7 @@ module Low
37
39
  @seconds = seconds
38
40
  @at_hour = at_hour
39
41
  @triggered_at = nil
42
+ @outcomes = {}
40
43
  end
41
44
 
42
45
  # Each tick starts a tree of its own so a job's events are let go like a request's.
@@ -53,16 +56,32 @@ module Low
53
56
  # the next. It's not due outside its hour.
54
57
  def due?(now)
55
58
  @turn ||= turn_at(now)
59
+ @first_turn ||= @turn
56
60
  return false if at_hour && now.hour != at_hour
57
61
 
58
62
  turn_at(now) > @turn
59
63
  end
60
64
 
61
- # Triggers its observers, marking the turn it's in as run.
65
+ # Triggers its observers, marking the turn it's in as run and noting whether it ran or failed.
62
66
  def tick(now = Time.now)
63
67
  @triggered_at = now
64
68
  @turn = turn_at(now)
69
+ note_outcome(:running)
65
70
  trigger
71
+ note_outcome(:ran)
72
+ rescue StandardError
73
+ note_outcome(:failed)
74
+ raise
75
+ end
76
+
77
+ # What happened on the turn under way at that time: running or ran or failed. It's skipped when the turn passed
78
+ # without running since the app started and nil for a turn still to come or from before.
79
+ def outcome_at(time, now: Time.now)
80
+ turn = turn_at(time)
81
+ return @outcomes[turn] if @outcomes.key?(turn)
82
+ return unless @first_turn && turn > @first_turn && turn < turn_at(now)
83
+
84
+ :skipped
66
85
  end
67
86
 
68
87
  # Whether one of its turns starts at that second.
@@ -77,6 +96,11 @@ module Low
77
96
 
78
97
  private
79
98
 
99
+ def note_outcome(outcome)
100
+ @outcomes[@turn] = outcome
101
+ @outcomes.shift while @outcomes.size > KEPT_OUTCOMES
102
+ end
103
+
80
104
  # How many turns have passed since the epoch on the server's clock.
81
105
  def turn_at(time)
82
106
  local_seconds(time) / seconds
data/lib/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Low
4
4
  module Loop
5
- VERSION = '0.8.16'
5
+ VERSION = '0.8.17'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowloop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.16
4
+ version: 0.8.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi