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 +4 -4
- data/README.md +34 -0
- 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 +1 -0
- metadata +6 -5
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/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)
|
data/lib/activejob-status.rb
CHANGED
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.
|
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-
|
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:
|
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
|