activejob-status 1.0.0 → 1.1.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a87cf9049d2e78bf3374c506ba99606dc7770a8e263fc12b1f74b64c7a67fab
4
- data.tar.gz: 2ae8982bdf6e66bf2002e02fe2df89bf8082ed5d765ca3f49864869b516fc14c
3
+ metadata.gz: c2126b98461087723d25a787999e46ad568131c528d8b38d49d437700e9ee640
4
+ data.tar.gz: 3cfa5a8c5783b0efef3f6f7db766681afe65ecad74ff2622b2104e1810c525cd
5
5
  SHA512:
6
- metadata.gz: 894b7c42328e39fc9c822edf12f32cb9d9c0e95b248e08dcdcfa19ad8151c9192561866e23185797cd7e6a21b811cb8c751fb884ed9143f698dcc13c6872f82f
7
- data.tar.gz: 1a7629d6f18764117de7bcb6643baad9f98c76b1ff91b7964cb6aa3b2d6197ebee49bb75cd38c9f9ac1a5dcd7576bf7bf7c0d91b442bda3ed7580d3d54b5aea8
6
+ metadata.gz: 98dd6128baae8b40dba1e6de09f4d71b3ea2eb0d41764cca7f58b0d5f2672ff7d8e71ffd9b8e670eb71adb91772eb763b2e06c55becd7404d9640611e130e072
7
+ data.tar.gz: 8340c579dbc672a62ca3821f9ded8c8f7a736ec87d476134fa96ed936c2988d83a2c3e612dca842f61cd5189e2385ca9022acce5a47696f411f59ea3a1fb3ca2
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 Savater Sebastien
1
+ Copyright (c) 2016-2024 Savater Sebastien
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -20,12 +20,9 @@ bundle add activejob-status
20
20
 
21
21
  ## Dependencies
22
22
 
23
- In future releases, `ActiveJob::Status` won't support [EOL versions](https://endoflife.date/rails) of `ActiveJob` & `ActiveSupport`.
24
-
25
- * Version `1.x` requires `ActiveSupport >= 6.0`
26
-
27
- If you're still using older Rails version, see [#24](https://github.com/inkstak/activejob-status/issues/24#issuecomment-1436046173).
23
+ ActiveJob::Status 1.x requires `ActiveSupport >= 6.0`
28
24
 
25
+ If you're still using an older version of Rails, see [v0.5.0](https://github.com/inkstak/activejob-status/releases/tag/v0.5.0).
29
26
 
30
27
  ## Configuration
31
28
 
@@ -387,6 +384,40 @@ class MyJob < ApplicationJob
387
384
  end
388
385
  ```
389
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
+
390
421
  ## Contributing
391
422
 
392
423
  1. Don't hesitate to submit your feature/idea/fix in [issues](https://github.com/inkstak/activejob-status)
@@ -403,20 +434,20 @@ bundle exec rubocop
403
434
  bundle exec standardrb
404
435
  ```
405
436
 
406
- All of them can be run with:
407
-
437
+ To run RSpec against various version of Rails dependencies:
408
438
  ```bash
409
- bundle exec rake
439
+ bundle exec appraisal install
440
+ bundle exec appraisal rspec
410
441
  ```
411
442
 
412
- To run test suite against various version of Rails dependencies:
443
+ All of them can be run with:
444
+
413
445
  ```bash
414
- bundle exec appraisal install
415
- bundle exec appraisal
446
+ bundle exec rake
416
447
  ```
417
448
 
418
449
  ## License & credits
419
450
 
420
- Please see [LICENSE](https://github.com/inkstak/coverart/blob/main/LICENSE) for further details.
451
+ Please see [LICENSE](https://github.com/inkstak/activejob-status/blob/main/LICENSE) for further details.
421
452
 
422
- Contributors: [./graphs/contributors](https://github.com/inkstak/coverart/graphs/contributors)
453
+ Contributors: [./graphs/contributors](https://github.com/inkstak/activejob-status/graphs/contributors)
@@ -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.0"
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
@@ -54,7 +55,7 @@ module ActiveJob
54
55
  end
55
56
 
56
57
  def store
57
- @@store ||= (defined?(Rails) && Rails.cache)
58
+ @@store ||= (Rails.cache if defined?(Rails))
58
59
  end
59
60
 
60
61
  def get(id)
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.0
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: 2023-03-03 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
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: '1.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: '1.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: timecop
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -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