activejob-status 1.0.0 → 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 +4 -4
- data/LICENSE +1 -1
- data/README.md +44 -13
- data/lib/activejob-status/batch.rb +31 -0
- data/lib/activejob-status/storage.rb +6 -0
- data/lib/activejob-status/version.rb +1 -1
- data/lib/activejob-status.rb +2 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2126b98461087723d25a787999e46ad568131c528d8b38d49d437700e9ee640
|
4
|
+
data.tar.gz: 3cfa5a8c5783b0efef3f6f7db766681afe65ecad74ff2622b2104e1810c525cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98dd6128baae8b40dba1e6de09f4d71b3ea2eb0d41764cca7f58b0d5f2672ff7d8e71ffd9b8e670eb71adb91772eb763b2e06c55becd7404d9640611e130e072
|
7
|
+
data.tar.gz: 8340c579dbc672a62ca3821f9ded8c8f7a736ec87d476134fa96ed936c2988d83a2c3e612dca842f61cd5189e2385ca9022acce5a47696f411f59ea3a1fb3ca2
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -20,12 +20,9 @@ bundle add activejob-status
|
|
20
20
|
|
21
21
|
## Dependencies
|
22
22
|
|
23
|
-
|
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
|
-
|
407
|
-
|
437
|
+
To run RSpec against various version of Rails dependencies:
|
408
438
|
```bash
|
409
|
-
bundle exec
|
439
|
+
bundle exec appraisal install
|
440
|
+
bundle exec appraisal rspec
|
410
441
|
```
|
411
442
|
|
412
|
-
|
443
|
+
All of them can be run with:
|
444
|
+
|
413
445
|
```bash
|
414
|
-
bundle exec
|
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/
|
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/
|
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)
|
data/lib/activejob-status.rb
CHANGED
@@ -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)
|
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:
|
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:
|
213
|
+
version: 1.3.1
|
213
214
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
215
|
+
rubygems_version: 3.4.6
|
215
216
|
signing_key:
|
216
217
|
specification_version: 4
|
217
218
|
summary: Monitor your jobs
|