tlq-client 0.2.0 → 0.4.0

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: 23e82549788eabfb735a5035d8b8f478df7e570a6b1c43338ea28714f2ef0824
4
- data.tar.gz: 584f2eb0f74e20b8df96401630c5843184c15b31f48e693739f159f5ba22f42a
3
+ metadata.gz: 40f40f39e20c3a46bb0d6cc6a5517fbb2d581e4996893307bffc84582f90bb15
4
+ data.tar.gz: 0f1686b89b1306f27866738e029709ec1e58d736ae87363f67660a1e7edcad1a
5
5
  SHA512:
6
- metadata.gz: a2da29977ea8ea209bcd448c8928b59e58ef76c3bf0b55ce0f8008edd9a12070832eb3af46c1c5c350cefee41484a43f41dc279ab7b78effa0c928e84de05645
7
- data.tar.gz: 44d102142b0750efca0db88d4f7fba9f9cf8891117c8456bf852604a0eb59d65f63b6e590b6b9a4da8ffd034449e771d230a19423a4d4a813f46f13c05684c4d
6
+ metadata.gz: 0da8db4deaf928c53ebd6f2caf1973054efe290b556253bfe022a4c2f8eaa3e27eabd64e474a18f83922ffb56c3ec50bd6b9ffd9151c32064f7e62f0fc86f578
7
+ data.tar.gz: 3863fa188edd2a85f074a9da0cf7e219f3c5528f4b4c3a1fcb41fb0ae74aab0d62b564044d419591a0bebee9f2f34ad2ec5f2459a9955b26b517aaea189bb157
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.4.0] - 2026-03-21
9
+
10
+ ### Added
11
+
12
+ - `stats` - Get queue statistics (ready, processing, dead counts)
13
+
8
14
  ## [0.2.0] - 2025-11-26
9
15
 
10
16
  ### Added
data/README.md CHANGED
@@ -30,7 +30,7 @@ require 'tlq_client'
30
30
  # Initialize client (defaults to localhost:1337)
31
31
  client = TLQClient.new
32
32
  # or with custom host/port
33
- client = TLQClient.new(host: 'queue.example.com', port: 8080)
33
+ client = TLQClient.new(host: 'tlq.skyak.tech', port: 8080)
34
34
 
35
35
  # Add messages to the queue
36
36
  message = client.add_message("Process order #123")
@@ -58,6 +58,10 @@ ids = messages.map { |m| m['id'] }
58
58
  client.delete_messages(ids) # Delete multiple
59
59
  client.retry_messages(ids) # Retry multiple
60
60
 
61
+ # Queue statistics
62
+ stats = client.stats
63
+ puts stats # => {"ready" => 10, "processing" => 2, "dead" => 0}
64
+
61
65
  # Health check
62
66
  client.health_check # => true
63
67
 
@@ -100,13 +104,17 @@ Returns messages to the queue for reprocessing. Increments `retry_count`. Accept
100
104
 
101
105
  Removes all messages from the queue. Cannot be undone.
102
106
 
107
+ ### `stats → Hash`
108
+
109
+ Returns queue statistics with `ready`, `processing`, and `dead` counts.
110
+
103
111
  ### `health_check → Boolean`
104
112
 
105
113
  Returns `true` if the TLQ server is reachable.
106
114
 
107
115
  ## Requirements
108
116
 
109
- - Ruby >= 2.6
117
+ - Ruby >= 3.1
110
118
  - Running [TLQ server](https://github.com/skyaktech/tlq)
111
119
 
112
120
  ## Development
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TLQClient
4
- VERSION = "0.2.0"
4
+ # The current version of the TLQClient gem.
5
+ # @return [String] the semantic version string
6
+ VERSION = "0.4.0"
5
7
  end
data/lib/tlq_client.rb CHANGED
@@ -5,16 +5,67 @@ require 'net/http'
5
5
  require 'uri'
6
6
  require_relative 'tlq_client/version'
7
7
 
8
+ # A client library for communicating with a TLQ (Tiny Little Queue) server.
9
+ #
10
+ # TLQClient provides a simple interface for message queue operations including
11
+ # adding, retrieving, deleting, and retrying messages.
12
+ #
13
+ # @example Basic usage
14
+ # client = TLQClient.new(host: 'localhost', port: 1337)
15
+ #
16
+ # # Add a message
17
+ # message = client.add_message("Hello, TLQ!")
18
+ #
19
+ # # Retrieve messages
20
+ # messages = client.get_messages(5)
21
+ #
22
+ # # Process and delete
23
+ # ids = messages.map { |m| m['id'] }
24
+ # client.delete_messages(ids)
25
+ #
26
+ # @see https://github.com/robinbakker/tiny-little-queue TLQ Server
8
27
  class TLQClient
9
- attr_reader :host, :port, :base_uri
28
+ # @return [String] the hostname of the TLQ server
29
+ attr_reader :host
10
30
 
31
+ # @return [Integer] the port number of the TLQ server
32
+ attr_reader :port
33
+
34
+ # @return [String] the base URI for API requests
35
+ attr_reader :base_uri
36
+
37
+ # Creates a new TLQClient instance.
38
+ #
39
+ # @param host [String] the hostname of the TLQ server (default: 'localhost')
40
+ # @param port [Integer] the port number of the TLQ server (default: 1337)
41
+ #
42
+ # @example Connect to default server
43
+ # client = TLQClient.new
44
+ #
45
+ # @example Connect to custom server
46
+ # client = TLQClient.new(host: 'tlq.skyak.tech', port: 8080)
11
47
  def initialize(host: 'localhost', port: 1337)
12
48
  @host = host
13
49
  @port = port
14
50
  @base_uri = "http://#{@host}:#{@port}"
15
51
  end
16
52
 
17
- # Add a message to the queue
53
+ # Adds a message to the queue.
54
+ #
55
+ # @param body [String, Hash, Array] the message body to add to the queue.
56
+ # Can be a string or any JSON-serializable object.
57
+ #
58
+ # @return [Hash] the created message object containing 'id', 'body', and metadata
59
+ #
60
+ # @raise [RuntimeError] if the server response cannot be parsed as JSON
61
+ # @raise [RuntimeError] if the HTTP request fails
62
+ #
63
+ # @example Add a simple string message
64
+ # message = client.add_message("Hello, World!")
65
+ # puts message['id'] # => "abc123"
66
+ #
67
+ # @example Add a hash message
68
+ # message = client.add_message({ event: 'user_signup', user_id: 42 })
18
69
  def add_message(body)
19
70
  response = post('/add', { body: body })
20
71
  JSON.parse(response.body)
@@ -24,7 +75,26 @@ class TLQClient
24
75
  raise "HTTP request failed: #{e.message}"
25
76
  end
26
77
 
27
- # Get messages from the queue
78
+ # Retrieves messages from the queue.
79
+ #
80
+ # Messages are leased to the client and must be either deleted (to acknowledge
81
+ # successful processing) or retried (to return them to the queue).
82
+ #
83
+ # @param count [Integer] the number of messages to retrieve (default: 1)
84
+ #
85
+ # @return [Array<Hash>] an array of message objects, each containing 'id' and 'body'
86
+ #
87
+ # @raise [RuntimeError] if the server response cannot be parsed as JSON
88
+ # @raise [RuntimeError] if the HTTP request fails
89
+ #
90
+ # @example Get a single message
91
+ # messages = client.get_messages
92
+ # message = messages.first
93
+ # puts message['body']
94
+ #
95
+ # @example Get multiple messages
96
+ # messages = client.get_messages(10)
97
+ # messages.each { |m| process(m) }
28
98
  def get_messages(count = 1)
29
99
  response = post('/get', { count: count })
30
100
  parsed = JSON.parse(response.body)
@@ -35,7 +105,22 @@ class TLQClient
35
105
  raise "HTTP request failed: #{e.message}"
36
106
  end
37
107
 
38
- # Delete messages from the queue
108
+ # Deletes messages from the queue permanently.
109
+ #
110
+ # Use this method to acknowledge successful processing of messages.
111
+ # Once deleted, messages cannot be recovered.
112
+ #
113
+ # @param ids [String, Array<String>] a single message ID or array of message IDs to delete
114
+ #
115
+ # @return [Boolean] true if the deletion was successful
116
+ #
117
+ # @raise [RuntimeError] if the HTTP request fails
118
+ #
119
+ # @example Delete a single message
120
+ # client.delete_messages("abc123")
121
+ #
122
+ # @example Delete multiple messages
123
+ # client.delete_messages(["abc123", "def456", "ghi789"])
39
124
  def delete_messages(ids)
40
125
  response = post('/delete', { ids: Array(ids) })
41
126
  response.body == '"Success"'
@@ -43,7 +128,22 @@ class TLQClient
43
128
  raise "HTTP request failed: #{e.message}"
44
129
  end
45
130
 
46
- # Retry messages (return to queue)
131
+ # Returns messages to the queue for reprocessing.
132
+ #
133
+ # Use this method when message processing fails and you want to retry later.
134
+ # The messages will be returned to the queue and can be retrieved again.
135
+ #
136
+ # @param ids [String, Array<String>] a single message ID or array of message IDs to retry
137
+ #
138
+ # @return [Boolean] true if the retry was successful
139
+ #
140
+ # @raise [RuntimeError] if the HTTP request fails
141
+ #
142
+ # @example Retry a single message
143
+ # client.retry_messages("abc123")
144
+ #
145
+ # @example Retry multiple messages
146
+ # client.retry_messages(["abc123", "def456"])
47
147
  def retry_messages(ids)
48
148
  response = post('/retry', { ids: Array(ids) })
49
149
  response.body == '"Success"'
@@ -51,7 +151,16 @@ class TLQClient
51
151
  raise "HTTP request failed: #{e.message}"
52
152
  end
53
153
 
54
- # Purge all messages from the queue
154
+ # Purges all messages from the queue.
155
+ #
156
+ # @note This operation is irreversible. All messages will be permanently deleted.
157
+ #
158
+ # @return [Boolean] true if the purge was successful
159
+ #
160
+ # @raise [RuntimeError] if the HTTP request fails
161
+ #
162
+ # @example Clear the queue
163
+ # client.purge_queue
55
164
  def purge_queue
56
165
  response = post('/purge', {})
57
166
  response.body == '"Success"'
@@ -59,7 +168,36 @@ class TLQClient
59
168
  raise "HTTP request failed: #{e.message}"
60
169
  end
61
170
 
62
- # Check server health
171
+ # Returns queue statistics from the TLQ server.
172
+ #
173
+ # @return [Hash] queue statistics containing 'ready', 'processing', and 'dead' counts
174
+ #
175
+ # @raise [RuntimeError] if the server response cannot be parsed as JSON
176
+ # @raise [RuntimeError] if the HTTP request fails
177
+ #
178
+ # @example Get queue stats
179
+ # stats = client.stats
180
+ # puts "Ready: #{stats['ready']}, Processing: #{stats['processing']}, Dead: #{stats['dead']}"
181
+ def stats
182
+ uri = URI("#{@base_uri}/stats")
183
+ response = Net::HTTP.get_response(uri)
184
+ JSON.parse(response.body)
185
+ rescue JSON::ParserError => e
186
+ raise "Failed to parse response: #{e.message}"
187
+ rescue StandardError => e
188
+ raise "HTTP request failed: #{e.message}"
189
+ end
190
+
191
+ # Checks if the TLQ server is reachable and responding.
192
+ #
193
+ # @return [Boolean] true if the server is healthy and responding
194
+ #
195
+ # @raise [RuntimeError] if the health check request fails
196
+ #
197
+ # @example Check server status
198
+ # if client.health_check
199
+ # puts "Server is running"
200
+ # end
63
201
  def health_check
64
202
  uri = URI("#{@base_uri}/hello")
65
203
  response = Net::HTTP.get_response(uri)
@@ -70,6 +208,14 @@ class TLQClient
70
208
 
71
209
  private
72
210
 
211
+ # Sends a POST request to the TLQ server.
212
+ #
213
+ # @param path [String] the API endpoint path
214
+ # @param data [Hash] the request body data to send as JSON
215
+ #
216
+ # @return [Net::HTTPResponse] the HTTP response object
217
+ #
218
+ # @api private
73
219
  def post(path, data)
74
220
  uri = URI("#{@base_uri}#{path}")
75
221
  http = Net::HTTP.new(uri.host, uri.port)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tlq-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nebojsa Jakovljevic
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-26 00:00:00.000000000 Z
11
+ date: 2026-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
55
69
  description: A Ruby client library to interact with TLQ message queue
56
70
  email:
57
71
  - nebojsa@skyak.tech
@@ -71,7 +85,8 @@ metadata:
71
85
  homepage_uri: https://tinylittlequeue.app/
72
86
  source_code_uri: https://github.com/skyaktech/tlq-client-ruby
73
87
  changelog_uri: https://github.com/skyaktech/tlq-client-ruby/blob/main/CHANGELOG.md
74
- post_install_message:
88
+ documentation_uri: https://rubydoc.info/gems/tlq-client
89
+ post_install_message:
75
90
  rdoc_options: []
76
91
  require_paths:
77
92
  - lib
@@ -79,15 +94,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
94
  requirements:
80
95
  - - ">="
81
96
  - !ruby/object:Gem::Version
82
- version: 2.6.0
97
+ version: 3.1.0
83
98
  required_rubygems_version: !ruby/object:Gem::Requirement
84
99
  requirements:
85
100
  - - ">="
86
101
  - !ruby/object:Gem::Version
87
102
  version: '0'
88
103
  requirements: []
89
- rubygems_version: 3.0.3.1
90
- signing_key:
104
+ rubygems_version: 3.4.19
105
+ signing_key:
91
106
  specification_version: 4
92
107
  summary: Ruby client for TLQ (Tiny Little Queue)
93
108
  test_files: []