zizq 0.1.0 → 0.2.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: 77ab05fe491ab193d0c5c3b1106aac3e5effe7b1dcb7e0117b70e0e05652426b
4
- data.tar.gz: 05f26bd94ca2127e7e859212348e063bc9354d866945ae500514dcfbcfe57828
3
+ metadata.gz: fb5651af26b76aeb9da0d00636cb1c2f10479c544c52083d16436f46670ba346
4
+ data.tar.gz: 30b0a1142d96c565d11ef4252f07305e6ef55ac264217a8540975236ae007958
5
5
  SHA512:
6
- metadata.gz: f12216566271dbd68395eeada829ffd68bfd853e86c1a8e598dbac6c3c7f5d8af5008ee084a9a7ebaef99d74144c6d05995fe32e01f0349b47dac6beb082c702
7
- data.tar.gz: 505804d9abd2c1cff8a749bd9cb6ad3d224d09545648a314b54a3094a96f2d18cb18257661833479bf1b59959d6d300730e2cbcbb70572afee5195bb538d8460
6
+ metadata.gz: 73d90b0c47f1dcf3452d573829211d69f853b38aca8d0b7e14be74017ac9b802f3faa9151f11ae1fcc0644a574d0b91dc308eec7c8fd560dccf93e1ab31ef321
7
+ data.tar.gz: '0843a45519c6d0c6256450e242887a08489fdfb84040f6f302ba615118e5dfb9171cc52db1e5407446d0caa4012ff3b136a583f421c19ea3cd0fe6ba92a38371'
data/lib/zizq/client.rb CHANGED
@@ -249,6 +249,37 @@ module Zizq
249
249
  Resources::JobPage.new(self, data)
250
250
  end
251
251
 
252
+ # Count jobs matching the given filters.
253
+ #
254
+ # Accepts the same filter arguments as `list_jobs` (minus pagination).
255
+ # Returns the count as an integer.
256
+ #
257
+ # @rbs id: (String | Array[String])?
258
+ # @rbs status: (String | Array[String])?
259
+ # @rbs queue: (String | Array[String])?
260
+ # @rbs type: (String | Array[String])?
261
+ # @rbs filter: String?
262
+ # @rbs return: Integer
263
+ def count_jobs(id: nil,
264
+ status: nil,
265
+ queue: nil,
266
+ type: nil,
267
+ filter: nil)
268
+ options = { id:, status:, queue:, type:, filter: }.compact #: Hash[Symbol, untyped]
269
+
270
+ multi_keys = %i[id status queue type]
271
+ params = build_where_params(options, multi_keys:)
272
+
273
+ # An empty filter ([] or "") matches nothing — short-circuit.
274
+ multi_keys.each do |key|
275
+ return 0 if params[key] == ""
276
+ end
277
+
278
+ response = get("/jobs/count", params:)
279
+ data = handle_response!(response, expected: 200)
280
+ data.fetch("count")
281
+ end
282
+
252
283
  # Delete a single job by ID.
253
284
  #
254
285
  # @rbs id: String
data/lib/zizq/query.rb CHANGED
@@ -283,6 +283,32 @@ module Zizq
283
283
  limit(2).to_a.size == 1
284
284
  end
285
285
 
286
+ # Count matching jobs via the server-side count endpoint.
287
+ #
288
+ # Without a block or argument, uses `GET /jobs/count` for an efficient
289
+ # server-side count. When a limit is set, caps the result locally with
290
+ # `[total, limit].min`.
291
+ #
292
+ # With a block or argument, falls back to Enumerable (iterates and counts
293
+ # matching jobs).
294
+ #
295
+ # @rbs *args: untyped
296
+ # @rbs &block: ?(Resources::Job) -> bool
297
+ # @rbs return: Integer
298
+ def count(*args, &block)
299
+ return super if block || !args.empty?
300
+
301
+ total = Zizq.client.count_jobs(
302
+ id: @id,
303
+ queue: @queue,
304
+ type: @type,
305
+ status: @status,
306
+ filter: @jq_filter,
307
+ )
308
+
309
+ @limit ? [total, @limit].min : total
310
+ end
311
+
286
312
  # Iterate over matching jobs in reverse order.
287
313
  #
288
314
  # Optimised: pushes the reverse ordering to the server instead of
data/lib/zizq/version.rb CHANGED
@@ -5,5 +5,5 @@
5
5
  # frozen_string_literal: true
6
6
 
7
7
  module Zizq
8
- VERSION = "0.1.0" #: String
8
+ VERSION = "0.2.0" #: String
9
9
  end
@@ -108,6 +108,19 @@ module Zizq
108
108
  # @rbs return: Resources::JobPage
109
109
  def list_jobs: (?id: (String | Array[String])?, ?status: (String | Array[String])?, ?queue: (String | Array[String])?, ?type: (String | Array[String])?, ?filter: String?, ?from: String?, ?order: Zizq::sort_direction?, ?limit: Integer?) -> Resources::JobPage
110
110
 
111
+ # Count jobs matching the given filters.
112
+ #
113
+ # Accepts the same filter arguments as `list_jobs` (minus pagination).
114
+ # Returns the count as an integer.
115
+ #
116
+ # @rbs id: (String | Array[String])?
117
+ # @rbs status: (String | Array[String])?
118
+ # @rbs queue: (String | Array[String])?
119
+ # @rbs type: (String | Array[String])?
120
+ # @rbs filter: String?
121
+ # @rbs return: Integer
122
+ def count_jobs: (?id: (String | Array[String])?, ?status: (String | Array[String])?, ?queue: (String | Array[String])?, ?type: (String | Array[String])?, ?filter: String?) -> Integer
123
+
111
124
  # Delete a single job by ID.
112
125
  #
113
126
  # @rbs id: String
@@ -208,6 +208,20 @@ module Zizq
208
208
  # @rbs return: bool
209
209
  def one?: () ?{ (Resources::Job) -> bool } -> bool
210
210
 
211
+ # Count matching jobs via the server-side count endpoint.
212
+ #
213
+ # Without a block or argument, uses `GET /jobs/count` for an efficient
214
+ # server-side count. When a limit is set, caps the result locally with
215
+ # `[total, limit].min`.
216
+ #
217
+ # With a block or argument, falls back to Enumerable (iterates and counts
218
+ # matching jobs).
219
+ #
220
+ # @rbs *args: untyped
221
+ # @rbs &block: ?(Resources::Job) -> bool
222
+ # @rbs return: Integer
223
+ def count: (*untyped args) ?{ (Resources::Job) -> bool } -> Integer
224
+
211
225
  # Iterate over matching jobs in reverse order.
212
226
  #
213
227
  # Optimised: pushes the reverse ordering to the server instead of
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zizq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Corbyn <chris@zizq.io>
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-25 00:00:00.000000000 Z
11
+ date: 2026-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http