activejob-status 1.0.1 → 1.1.0.beta.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: 843334651f7e39f88ff267202ef1d7bbe239705be4dd5507e97b5c1dcdcd79b6
4
- data.tar.gz: 285ec915bd5eddbd58f83ef557beaf7798a59c9def6b2a7437af1d4a26e9ed58
3
+ metadata.gz: c2126b98461087723d25a787999e46ad568131c528d8b38d49d437700e9ee640
4
+ data.tar.gz: 3cfa5a8c5783b0efef3f6f7db766681afe65ecad74ff2622b2104e1810c525cd
5
5
  SHA512:
6
- metadata.gz: 2d56a7a5b689688deef228d0ec8e7a6ebd68188bf45a9881da5adeddcb7fa2f6ec8baebe7821208c75140015b318b5cb01e23496dd23a7a1baef367b3111f69e
7
- data.tar.gz: 35bb63ac0aac832ed79ce3437731b944a3307193ecffdc502d85c2b9b00cdba0769eac511502411b6f7fa81920d621fd624e9b2f4fc3f8a1dbce970910385b8b
6
+ metadata.gz: 98dd6128baae8b40dba1e6de09f4d71b3ea2eb0d41764cca7f58b0d5f2672ff7d8e71ffd9b8e670eb71adb91772eb763b2e06c55becd7404d9640611e130e072
7
+ data.tar.gz: 8340c579dbc672a62ca3821f9ded8c8f7a736ec87d476134fa96ed936c2988d83a2c3e612dca842f61cd5189e2385ca9022acce5a47696f411f59ea3a1fb3ca2
data/README.md CHANGED
@@ -384,6 +384,40 @@ class MyJob < ApplicationJob
384
384
  end
385
385
  ```
386
386
 
387
+ ### [Beta] Batches
388
+
389
+ > **Warning** : The Batch API is available in beta:
390
+ >
391
+ > ```bash
392
+ > gem install activejob-status --pre
393
+ > # or
394
+ > bundle add activejob-status --version "~> 1.1.0.beta.0"
395
+ > ```
396
+ >
397
+ > It doesn't provide all features implemented by backends
398
+ > like [Sidekiq](https://github.com/sidekiq/sidekiq/wiki/Batches)
399
+ > or [GoodJob](https://github.com/bensheldon/good_job?tab=readme-ov-file#batches).
400
+ > Moreover, it wasn't designed to support batches with hundreds of jobs.
401
+ >
402
+
403
+ ActiveJob::Status provides a naïve implementation of batches:
404
+
405
+ ```ruby
406
+ job_1 = MyJob.perform_later
407
+ job_2 = MyJob.perform_later
408
+
409
+ batch = ActiveJob::Status::Batch.new([job_1, job_2])
410
+ batch.status # => "working"
411
+ ```
412
+
413
+ The batch status is considered:
414
+
415
+ * `queued` if **all** of the jobs are `queued`
416
+ * `failed` if **one** of the jobs is `failed`
417
+ * `completed` if **all** of the jobs are `completed`
418
+ * `working` in all other circumstances
419
+
420
+
387
421
  ## Contributing
388
422
 
389
423
  1. Don't hesitate to submit your feature/idea/fix in [issues](https://github.com/inkstak/activejob-status)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveJob
4
+ module Status
5
+ class Batch
6
+ def initialize(jobs)
7
+ @jobs = jobs
8
+ @storage = ActiveJob::Status::Storage.new
9
+ end
10
+
11
+ def status
12
+ statuses = read.values.pluck(:status)
13
+
14
+ if statuses.include?(:failed)
15
+ :failed
16
+ elsif statuses.all?(:queued)
17
+ :queued
18
+ elsif statuses.all?(:completed)
19
+ :completed
20
+ else
21
+ :working
22
+ end
23
+ end
24
+
25
+ def read
26
+ @storage.read_multi(@jobs)
27
+ end
28
+ alias_method :to_h, :read
29
+ end
30
+ end
31
+ end
@@ -26,6 +26,12 @@ module ActiveJob
26
26
  store.read(key(job)) || {}
27
27
  end
28
28
 
29
+ def read_multi(jobs)
30
+ keys = jobs.map { |job| key(job) }
31
+ data = store.read_multi(*keys)
32
+ keys.index_with { |k| data.fetch(k, {}) }
33
+ end
34
+
29
35
  def write(job, message, force: false)
30
36
  @throttle.wrap(force: force) do
31
37
  store.write(key(job), message, expires_in: @expires_in)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveJob
4
4
  module Status
5
- VERSION = "1.0.1"
5
+ VERSION = "1.1.0.beta.0"
6
6
  end
7
7
  end
@@ -8,6 +8,7 @@ require "activejob-status/storage"
8
8
  require "activejob-status/status"
9
9
  require "activejob-status/progress"
10
10
  require "activejob-status/throttle"
11
+ require "activejob-status/batch"
11
12
 
12
13
  module ActiveJob
13
14
  module Status
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Savater Sebastien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-12 00:00:00.000000000 Z
11
+ date: 2024-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -187,6 +187,7 @@ files:
187
187
  - LICENSE
188
188
  - README.md
189
189
  - lib/activejob-status.rb
190
+ - lib/activejob-status/batch.rb
190
191
  - lib/activejob-status/progress.rb
191
192
  - lib/activejob-status/status.rb
192
193
  - lib/activejob-status/storage.rb
@@ -207,11 +208,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
208
  version: '0'
208
209
  required_rubygems_version: !ruby/object:Gem::Requirement
209
210
  requirements:
210
- - - ">="
211
+ - - ">"
211
212
  - !ruby/object:Gem::Version
212
- version: '0'
213
+ version: 1.3.1
213
214
  requirements: []
214
- rubygems_version: 3.1.6
215
+ rubygems_version: 3.4.6
215
216
  signing_key:
216
217
  specification_version: 4
217
218
  summary: Monitor your jobs