lowloop 0.8.19 → 0.8.21
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/connections/connection_manager.rb +1 -3
- data/lib/connections/request_parser.rb +6 -6
- data/lib/intervals/interval.rb +20 -14
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e074495089aa24b296af09830d3cbaf66544569591a681d43f10d2ca87144e6
|
|
4
|
+
data.tar.gz: 047246a6cf59057f058dd6db23faf934840164811d6ff8f7e67fdfdcacab26d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8743afc5bf62e3de5f6b41e0f3d94e6e273410871214d5a08f85a66d1e78ef0ee962835647cefdfc5760f3d07d6eea50da6246e5d0ad0e641c8d918bbe99736
|
|
7
|
+
data.tar.gz: 29d7c9d5e5a93c8ef3d466531db8e5b4bb6971e0d66fd963a2f76c26af2daa905e6c240fe4c26529f089f8b72f0038e4676c223824718c09e1daf4b9b8576aa7
|
|
@@ -45,14 +45,13 @@ module Low
|
|
|
45
45
|
def serve_requests(socket:)
|
|
46
46
|
stream = RequestParser.create_stream(socket:)
|
|
47
47
|
keep_alive = true
|
|
48
|
-
version = nil
|
|
49
48
|
|
|
50
49
|
while keep_alive
|
|
51
50
|
break unless socket.wait_readable(keep_alive_timeout)
|
|
52
51
|
|
|
53
52
|
socket.timeout = request_timeout
|
|
54
53
|
begin
|
|
55
|
-
request = RequestParser.parse(stream:, host: config.host, port: config.port
|
|
54
|
+
request = RequestParser.parse(stream:, host: config.host, port: config.port)
|
|
56
55
|
rescue IO::TimeoutError
|
|
57
56
|
break
|
|
58
57
|
ensure
|
|
@@ -60,7 +59,6 @@ module Low
|
|
|
60
59
|
end
|
|
61
60
|
break if request.nil?
|
|
62
61
|
|
|
63
|
-
version ||= request.version
|
|
64
62
|
unless headers_valid?(request)
|
|
65
63
|
ResponseBuilder.respond(socket:, response: ResponseFactory.status(code: 400), keep_alive: false)
|
|
66
64
|
break
|
|
@@ -16,13 +16,11 @@ module Low
|
|
|
16
16
|
IO::Stream(socket)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def parse(stream: IO::Stream::Generic, host: String, port: Integer
|
|
20
|
-
version ||= Async::HTTP::Protocol::HTTP.default.protocol_for(stream)::VERSION
|
|
21
|
-
|
|
19
|
+
def parse(stream: IO::Stream::Generic, host: String, port: Integer) -> { ::Protocol::HTTP::Request | nil }
|
|
22
20
|
result = parse_request(stream:)
|
|
23
21
|
return nil unless result
|
|
24
22
|
|
|
25
|
-
method, full_path = result
|
|
23
|
+
method, full_path, version = result
|
|
26
24
|
headers = parse_headers(stream:)
|
|
27
25
|
body = parse_body(stream:, method:, headers:)
|
|
28
26
|
|
|
@@ -49,7 +47,7 @@ module Low
|
|
|
49
47
|
# :header_3\r\n
|
|
50
48
|
# \r\n
|
|
51
49
|
# :body
|
|
52
|
-
# The line is read into a new string
|
|
50
|
+
# The line is read into a new string so it's stripped in place. A line without a version is an HTTP/1.0 client's.
|
|
53
51
|
def parse_request(stream: IO::Stream::Generic)
|
|
54
52
|
request_line = stream.gets || return
|
|
55
53
|
|
|
@@ -59,7 +57,9 @@ module Low
|
|
|
59
57
|
method_end = request_line.index(' ') || request_line.length
|
|
60
58
|
path_end = request_line.index(' ', method_end + 1) || request_line.length
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
version = request_line[path_end + 1..]
|
|
61
|
+
version = 'HTTP/1.0' if version.nil? || version.empty?
|
|
62
|
+
[request_line[0, method_end], request_line[method_end + 1, path_end - method_end - 1], version]
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def parse_headers(stream: IO::Stream::Generic) -> { ::Protocol::HTTP::Headers }
|
data/lib/intervals/interval.rb
CHANGED
|
@@ -11,8 +11,11 @@ module Low
|
|
|
11
11
|
#
|
|
12
12
|
# Interval[every_second: 30]
|
|
13
13
|
# Interval[every_minute: 3, at_hour: 2]
|
|
14
|
+
#
|
|
15
|
+
# A tick that finds nothing to do can return Interval::IDLE, so its turn shows as idle rather than ran.
|
|
14
16
|
class Interval < Low::Event
|
|
15
17
|
UNITS = { every_second: 1, every_minute: 60, every_hour: 3600, every_day: 86_400 }.freeze
|
|
18
|
+
IDLE = :idle
|
|
16
19
|
# Enough recent turns' outcomes for a dial of up to 60 marks like each second of a minute.
|
|
17
20
|
KEPT_OUTCOMES = 64
|
|
18
21
|
|
|
@@ -62,23 +65,22 @@ module Low
|
|
|
62
65
|
turn_at(now) > @turn
|
|
63
66
|
end
|
|
64
67
|
|
|
65
|
-
# Triggers its observers, marking the turn it's in as run and noting
|
|
68
|
+
# Triggers its observers one after another, marking the turn it's in as run and noting how each one's went: ran,
|
|
69
|
+
# idle when it returned IDLE, or failed, which stops the rest.
|
|
66
70
|
def tick(now = Time.now)
|
|
67
71
|
@triggered_at = now
|
|
68
72
|
@turn = turn_at(now)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
rescue StandardError
|
|
73
|
-
note_outcome(:failed)
|
|
74
|
-
raise
|
|
73
|
+
@outcomes[@turn] = {}
|
|
74
|
+
@outcomes.shift while @outcomes.size > KEPT_OUTCOMES
|
|
75
|
+
run_in_tree { Observers::Keys[@key].observers.each { |observer| tick_observer(observer) } }
|
|
75
76
|
end
|
|
76
77
|
|
|
77
|
-
# What happened on the turn under way at that time: running
|
|
78
|
-
# without running since the app started and nil for a turn still to come
|
|
79
|
-
|
|
78
|
+
# What happened to an observer, by its object, on the turn under way at that time: running, ran, idle or failed.
|
|
79
|
+
# It's skipped when the turn passed without running since the app started, and nil for a turn still to come, from
|
|
80
|
+
# before, or that stopped before it.
|
|
81
|
+
def outcome_at(time, object, now: Time.now)
|
|
80
82
|
turn = turn_at(time)
|
|
81
|
-
return @outcomes[turn] if @outcomes.key?(turn)
|
|
83
|
+
return @outcomes[turn][object] if @outcomes.key?(turn)
|
|
82
84
|
return unless @first_turn && turn > @first_turn && turn < turn_at(now)
|
|
83
85
|
|
|
84
86
|
:skipped
|
|
@@ -96,9 +98,13 @@ module Low
|
|
|
96
98
|
|
|
97
99
|
private
|
|
98
100
|
|
|
99
|
-
def
|
|
100
|
-
@outcomes[@turn] =
|
|
101
|
-
|
|
101
|
+
def tick_observer(observer)
|
|
102
|
+
@outcomes[@turn][observer.object] = :running
|
|
103
|
+
result = observer.trigger(action: :tick, event: self)
|
|
104
|
+
@outcomes[@turn][observer.object] = result == IDLE ? :idle : :ran
|
|
105
|
+
rescue StandardError
|
|
106
|
+
@outcomes[@turn][observer.object] = :failed
|
|
107
|
+
raise
|
|
102
108
|
end
|
|
103
109
|
|
|
104
110
|
# How many turns have passed since the epoch on the server's clock.
|
data/lib/version.rb
CHANGED