leopard 0.2.4 → 0.2.6

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.
@@ -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
@@ -0,0 +1,17 @@
1
+ # HELP leopard_subject_busy_instances Instances currently processing a message on this subject
2
+ # TYPE leopard_subject_busy_instances gauge
3
+ <% subjects.each do |subject| -%>
4
+ leopard_subject_busy_instances{subject="<%= subject %>"} <%= busy[subject] %>
5
+ <% end -%>
6
+
7
+ # HELP leopard_subject_total_instances Total Leopard instances in this process
8
+ # TYPE leopard_subject_total_instances gauge
9
+ <% subjects.each do |subject| -%>
10
+ leopard_subject_total_instances{subject="<%= subject %>"} <%= total %>
11
+ <% end -%>
12
+
13
+ # HELP leopard_subject_pending_messages Messages pending processing across all instances
14
+ # TYPE leopard_subject_pending_messages gauge
15
+ <% subjects.each do |subject| -%>
16
+ leopard_subject_pending_messages{subject="<%= subject %>"} <%= pending[subject] %>
17
+ <% end -%>
@@ -3,7 +3,7 @@
3
3
  module Rubyists
4
4
  module Leopard
5
5
  # x-release-please-start-version
6
- VERSION = '0.2.4'
6
+ VERSION = '0.2.6'
7
7
  # x-release-please-end
8
8
  end
9
9
  end
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
@@ -0,0 +1,2 @@
1
+ [tools]
2
+ ruby = "latest"
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
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - bougyman
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-03-31 00:00:00.000000000 Z
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,12 +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
109
+ - lib/leopard/metrics_server.rb
106
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
107
115
  - lib/leopard/settings.rb
116
+ - lib/leopard/templates/prometheus_metrics.erb
108
117
  - lib/leopard/version.rb
118
+ - mise.toml
109
119
  homepage: https://github.com/rubyists/leopard
110
120
  licenses:
111
121
  - MIT
@@ -129,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
139
  - !ruby/object:Gem::Version
130
140
  version: '0'
131
141
  requirements: []
132
- rubygems_version: 3.6.2
142
+ rubygems_version: 4.0.6
133
143
  specification_version: 4
134
144
  summary: A server to supervise concurrent NATS ServiceApi workers.
135
145
  test_files: []