leopard 0.2.5 → 0.2.7
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/.release-please-manifest.json +1 -1
- data/.version.txt +1 -1
- data/.yardopts +5 -0
- data/CHANGELOG.md +14 -0
- data/Rakefile +110 -1
- data/Readme.adoc +61 -1
- data/ci/nats/start.sh +26 -1
- data/examples/echo_endpoint.rb +6 -0
- data/examples/jetstream_endpoint.rb +44 -0
- data/lib/leopard/errors.rb +10 -0
- data/lib/leopard/message_processor.rb +90 -0
- data/lib/leopard/message_wrapper.rb +4 -0
- data/lib/leopard/metrics_server.rb +49 -0
- data/lib/leopard/nats_api_server.rb +214 -57
- data/lib/leopard/nats_jetstream_callbacks.rb +76 -0
- data/lib/leopard/nats_jetstream_consumer.rb +186 -0
- data/lib/leopard/nats_jetstream_endpoint.rb +19 -0
- data/lib/leopard/nats_request_reply_callbacks.rb +70 -0
- data/lib/leopard/version.rb +1 -1
- data/lib/leopard.rb +17 -0
- data/mise.toml +2 -0
- metadata +11 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubyists
|
|
4
|
+
module Leopard
|
|
5
|
+
# Maps Leopard handler outcomes to request/reply response behavior.
|
|
6
|
+
class NatsRequestReplyCallbacks
|
|
7
|
+
# Builds a callback set for request/reply endpoint outcomes.
|
|
8
|
+
#
|
|
9
|
+
# @param logger [#error] Logger used for failure payloads.
|
|
10
|
+
#
|
|
11
|
+
# @return [void]
|
|
12
|
+
def initialize(logger:)
|
|
13
|
+
@logger = logger
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns transport callbacks for request/reply endpoints.
|
|
17
|
+
#
|
|
18
|
+
# @return [Hash{Symbol => #call}] Outcome callbacks keyed by `:on_success`, `:on_failure`, and `:on_error`.
|
|
19
|
+
def callbacks
|
|
20
|
+
{
|
|
21
|
+
on_success: method(:respond_with_success),
|
|
22
|
+
on_failure: method(:respond_with_failure),
|
|
23
|
+
on_error: method(:respond_with_error),
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# Responds to a successful request with the handler payload.
|
|
30
|
+
#
|
|
31
|
+
# @param wrapper [MessageWrapper] Wrapped request message.
|
|
32
|
+
# @param result [Dry::Monads::Success] Successful handler result.
|
|
33
|
+
#
|
|
34
|
+
# @return [void]
|
|
35
|
+
def respond_with_success(wrapper, result)
|
|
36
|
+
wrapper.respond(result.value!)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Responds to a failed request with the failure payload.
|
|
40
|
+
#
|
|
41
|
+
# @param wrapper [MessageWrapper] Wrapped request message.
|
|
42
|
+
# @param result [Dry::Monads::Failure] Failed handler result.
|
|
43
|
+
#
|
|
44
|
+
# @return [void]
|
|
45
|
+
def respond_with_failure(wrapper, result)
|
|
46
|
+
log_failure(result.failure)
|
|
47
|
+
wrapper.respond_with_error(result.failure)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Responds to a request with an exception payload after an unhandled error.
|
|
51
|
+
#
|
|
52
|
+
# @param wrapper [MessageWrapper] Wrapped request message.
|
|
53
|
+
# @param error [StandardError] The unhandled exception.
|
|
54
|
+
#
|
|
55
|
+
# @return [void]
|
|
56
|
+
def respond_with_error(wrapper, error)
|
|
57
|
+
wrapper.respond_with_error(error)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Logs the failure payload returned by a handler.
|
|
61
|
+
#
|
|
62
|
+
# @param failure [Object] The failure payload from the handler.
|
|
63
|
+
#
|
|
64
|
+
# @return [void]
|
|
65
|
+
def log_failure(failure)
|
|
66
|
+
@logger.error 'Error processing message: ', failure
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/lib/leopard/version.rb
CHANGED
data/lib/leopard.rb
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'dry/configurable'
|
|
4
|
+
require 'dry/monads'
|
|
4
5
|
require 'pathname'
|
|
5
6
|
require 'semantic_logger'
|
|
6
7
|
|
|
8
|
+
##
|
|
9
|
+
# Namespace for Leopard and related helper extensions.
|
|
7
10
|
class Pathname
|
|
11
|
+
# Joins the receiver with another path fragment.
|
|
12
|
+
#
|
|
13
|
+
# @param other [#to_s] The path fragment to append.
|
|
14
|
+
#
|
|
15
|
+
# @return [Pathname] The combined path.
|
|
8
16
|
def /(other)
|
|
9
17
|
join other.to_s
|
|
10
18
|
end
|
|
11
19
|
end
|
|
12
20
|
|
|
21
|
+
##
|
|
22
|
+
# Top-level namespace for Rubyists gems.
|
|
13
23
|
module Rubyists
|
|
24
|
+
##
|
|
25
|
+
# Namespace for Leopard runtime, DSL, and support classes.
|
|
14
26
|
module Leopard
|
|
15
27
|
end
|
|
16
28
|
end
|
|
@@ -18,3 +30,8 @@ end
|
|
|
18
30
|
require_relative 'leopard/settings'
|
|
19
31
|
require_relative 'leopard/version'
|
|
20
32
|
require_relative 'leopard/errors'
|
|
33
|
+
require_relative 'leopard/message_processor'
|
|
34
|
+
require_relative 'leopard/nats_jetstream_endpoint'
|
|
35
|
+
require_relative 'leopard/nats_jetstream_callbacks'
|
|
36
|
+
require_relative 'leopard/nats_jetstream_consumer'
|
|
37
|
+
require_relative 'leopard/nats_request_reply_callbacks'
|
data/mise.toml
ADDED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: leopard
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- bougyman
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: concurrent-ruby
|
|
@@ -91,6 +91,7 @@ files:
|
|
|
91
91
|
- ".release-please-manifest.json"
|
|
92
92
|
- ".rubocop.yml"
|
|
93
93
|
- ".version.txt"
|
|
94
|
+
- ".yardopts"
|
|
94
95
|
- CHANGELOG.md
|
|
95
96
|
- Rakefile
|
|
96
97
|
- Readme.adoc
|
|
@@ -100,14 +101,21 @@ files:
|
|
|
100
101
|
- ci/publish-gem.sh
|
|
101
102
|
- doc/service-api-vs-rest.adoc
|
|
102
103
|
- examples/echo_endpoint.rb
|
|
104
|
+
- examples/jetstream_endpoint.rb
|
|
103
105
|
- lib/leopard.rb
|
|
104
106
|
- lib/leopard/errors.rb
|
|
107
|
+
- lib/leopard/message_processor.rb
|
|
105
108
|
- lib/leopard/message_wrapper.rb
|
|
106
109
|
- lib/leopard/metrics_server.rb
|
|
107
110
|
- lib/leopard/nats_api_server.rb
|
|
111
|
+
- lib/leopard/nats_jetstream_callbacks.rb
|
|
112
|
+
- lib/leopard/nats_jetstream_consumer.rb
|
|
113
|
+
- lib/leopard/nats_jetstream_endpoint.rb
|
|
114
|
+
- lib/leopard/nats_request_reply_callbacks.rb
|
|
108
115
|
- lib/leopard/settings.rb
|
|
109
116
|
- lib/leopard/templates/prometheus_metrics.erb
|
|
110
117
|
- lib/leopard/version.rb
|
|
118
|
+
- mise.toml
|
|
111
119
|
homepage: https://github.com/rubyists/leopard
|
|
112
120
|
licenses:
|
|
113
121
|
- MIT
|
|
@@ -131,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
131
139
|
- !ruby/object:Gem::Version
|
|
132
140
|
version: '0'
|
|
133
141
|
requirements: []
|
|
134
|
-
rubygems_version:
|
|
142
|
+
rubygems_version: 4.0.6
|
|
135
143
|
specification_version: 4
|
|
136
144
|
summary: A server to supervise concurrent NATS ServiceApi workers.
|
|
137
145
|
test_files: []
|