lowloop 0.8.14 → 0.8.16
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/intervals/interval.rb +30 -4
- data/lib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53d6cf9b4dc4c2d7da0fafc75ea0a012f9c665de1a9707fc4f5cd0a6819eb0e2
|
|
4
|
+
data.tar.gz: 242c11146c4d2b3eda2f201a3181aa6b07bd0e683612eeb687e3d018236f76e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 80f3afccac6eef15e81c970681f09e147fbca0344f52decdc362bed8b69590fcf4e54e4ff34691742f6d5def18680cfb2c7f101795cb63677cc0277c64074406
|
|
7
|
+
data.tar.gz: 71349ca0269cb29052e40b077e6edd930d64f503c1ee7256e65878e2a830cb2b5977ac8f98baada742b117467bac93db8892f153c0bbd9bc8f4137104ed9a43b
|
data/lib/intervals/interval.rb
CHANGED
|
@@ -6,7 +6,8 @@ module Low
|
|
|
6
6
|
module Loop
|
|
7
7
|
# A schedule to observe to run code periodically, like "observe Interval[every_minute: 3]". LowLoop triggers each
|
|
8
8
|
# observed interval when it's due with the "tick" action, on a worker thread of its own, so a slow job never holds up
|
|
9
|
-
# requests.
|
|
9
|
+
# requests. Its turns follow the clock like :00 :03 :06 so restarting the app doesn't move them. With "at_hour: 2"
|
|
10
|
+
# it's only due during that hour of the day.
|
|
10
11
|
#
|
|
11
12
|
# Interval[every_second: 30]
|
|
12
13
|
# Interval[every_minute: 3, at_hour: 2]
|
|
@@ -43,23 +44,48 @@ module Low
|
|
|
43
44
|
true
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
#
|
|
47
|
+
# Its trees are kept apart so ticks never push the app's requests out of the event pool.
|
|
48
|
+
def internal?
|
|
49
|
+
true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Whether a turn has started since its last. The turn it's first seen in started before the app did so it waits for
|
|
53
|
+
# the next. It's not due outside its hour.
|
|
47
54
|
def due?(now)
|
|
55
|
+
@turn ||= turn_at(now)
|
|
48
56
|
return false if at_hour && now.hour != at_hour
|
|
49
57
|
|
|
50
|
-
|
|
58
|
+
turn_at(now) > @turn
|
|
51
59
|
end
|
|
52
60
|
|
|
53
|
-
# Triggers its observers,
|
|
61
|
+
# Triggers its observers, marking the turn it's in as run.
|
|
54
62
|
def tick(now = Time.now)
|
|
55
63
|
@triggered_at = now
|
|
64
|
+
@turn = turn_at(now)
|
|
56
65
|
trigger
|
|
57
66
|
end
|
|
58
67
|
|
|
68
|
+
# Whether one of its turns starts at that second.
|
|
69
|
+
def starts_turn?(time)
|
|
70
|
+
(local_seconds(time) % seconds).zero?
|
|
71
|
+
end
|
|
72
|
+
|
|
59
73
|
# The same schedule observed in two places is one interval, so both are triggered together.
|
|
60
74
|
def ==(other) = other.is_a?(Interval) && other.seconds == seconds && other.at_hour == at_hour
|
|
61
75
|
def eql?(other) = self == other
|
|
62
76
|
def hash = [self.class, seconds, at_hour].hash
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
# How many turns have passed since the epoch on the server's clock.
|
|
81
|
+
def turn_at(time)
|
|
82
|
+
local_seconds(time) / seconds
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Counts in the server's time zone so a day's turns start at its midnight.
|
|
86
|
+
def local_seconds(time)
|
|
87
|
+
time.to_i + time.utc_offset
|
|
88
|
+
end
|
|
63
89
|
end
|
|
64
90
|
end
|
|
65
91
|
end
|
data/lib/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.8.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -99,14 +99,14 @@ dependencies:
|
|
|
99
99
|
requirements:
|
|
100
100
|
- - ">="
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: 0.8.
|
|
102
|
+
version: 0.8.8
|
|
103
103
|
type: :runtime
|
|
104
104
|
prerelease: false
|
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
107
|
- - ">="
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: 0.8.
|
|
109
|
+
version: 0.8.8
|
|
110
110
|
- !ruby/object:Gem::Dependency
|
|
111
111
|
name: lowtype
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|