activejob-status 1.0.2 → 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: 42019a7ba3be192f9ced4e1edf6498fb81e26a61ffdbce26a488c13518a08595
4
- data.tar.gz: 8587b93b5aa1f16d77a7649efa3d9e4ef3c6cfe9c90642e37e1a662b20731397
3
+ metadata.gz: c2126b98461087723d25a787999e46ad568131c528d8b38d49d437700e9ee640
4
+ data.tar.gz: 3cfa5a8c5783b0efef3f6f7db766681afe65ecad74ff2622b2104e1810c525cd
5
5
  SHA512:
6
- metadata.gz: bc6ddddeb61c00b4f6ccfe2355b2c4d3f9409362bbd67637169b0ed3b31e2ffc1d33d4643370317f34089870d3e033cc1ad24b6275d45d1537e30893781a5b76
7
- data.tar.gz: 828dad588548826ec64114ced09b8c2ba784429fe8fab1496520aa1042a90cadf80fa0a7fee4b7565b432c2602c4d9bab5e5d5c30962bce211e8416cf95943b2
6
+ metadata.gz: 98dd6128baae8b40dba1e6de09f4d71b3ea2eb0d41764cca7f58b0d5f2672ff7d8e71ffd9b8e670eb71adb91772eb763b2e06c55becd7404d9640611e130e072
7
+ data.tar.gz: 8340c579dbc672a62ca3821f9ded8c8f7a736ec87d476134fa96ed936c2988d83a2c3e612dca842f61cd5189e2385ca9022acce5a47696f411f59ea3a1fb3ca2
data/README.md CHANGED
@@ -8,24 +8,6 @@ Simple monitoring status for ActiveJob, independent of your queuing backend or c
8
8
  [![Maintainability](https://api.codeclimate.com/v1/badges/a7b1ec1d3769e49021fd/maintainability)](https://codeclimate.com/github/inkstak/activejob-status/maintainability)
9
9
  [![Test Coverage](https://api.codeclimate.com/v1/badges/a7b1ec1d3769e49021fd/test_coverage)](https://codeclimate.com/github/inkstak/activejob-status/test_coverage)
10
10
 
11
- ## Table of contents
12
-
13
- - [Installation](#installation)
14
- - [Dependencies](#dependencies)
15
- - [Configuration](#configuration)
16
- - [Cache Store](#cache-store)
17
- - [Select data to store by default](#select-data-to-store-by-default)
18
- - [Expiration time](#expiration-time)
19
- - [Throttling](#throttling)
20
- - [Usage](#usage)
21
- - [Updating status](#updating-status)
22
- - [Data stored by default](#data-stored-by-default)
23
- - [Reading status](#reading-status)
24
- - [Serializing status to JSON](#serializing-status-to-json)
25
- - [Setting options per job](#setting-options-per-job)
26
- - [ActiveJob::Status and exceptions](#activejobstatus-and-exceptions)
27
- - [[Beta] Batches](#beta-batches)
28
-
29
11
  ## Installation
30
12
 
31
13
  ```bash
@@ -342,7 +324,7 @@ class MyJob < ActiveJob::Base
342
324
  end
343
325
  ```
344
326
 
345
- ### ActiveJob::Status and exceptions
327
+ ## ActiveJob::Status and exceptions
346
328
 
347
329
  Internally, ActiveJob::Status uses `ActiveSupport#rescue_from` to catch every `Exception` to apply the `failed` status
348
330
  before throwing the exception again.
@@ -404,7 +386,7 @@ end
404
386
 
405
387
  ### [Beta] Batches
406
388
 
407
- > **Warning** : The Batch API is available on [beta](https://github.com/inkstak/activejob-status/tree/beta):
389
+ > **Warning** : The Batch API is available in beta:
408
390
  >
409
391
  > ```bash
410
392
  > gem install activejob-status --pre
@@ -415,7 +397,7 @@ end
415
397
  > It doesn't provide all features implemented by backends
416
398
  > like [Sidekiq](https://github.com/sidekiq/sidekiq/wiki/Batches)
417
399
  > or [GoodJob](https://github.com/bensheldon/good_job?tab=readme-ov-file#batches).
418
- > Moreover, it wasn't designed to support batches with hundreds of jobs (or you might experience performanes issues).
400
+ > Moreover, it wasn't designed to support batches with hundreds of jobs.
419
401
  >
420
402
 
421
403
  ActiveJob::Status provides a naïve implementation of batches:
@@ -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
@@ -44,9 +44,7 @@ module ActiveJob
44
44
  end
45
45
 
46
46
  def progress
47
- read.then do |hash|
48
- hash[:progress].to_f / hash[:total].to_f
49
- end
47
+ read[:progress].to_f / read[:total].to_f
50
48
  end
51
49
 
52
50
  def present?
@@ -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.2"
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,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Savater Sebastien
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2024-04-18 00:00:00.000000000 Z
11
+ date: 2024-02-18 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: activejob
@@ -177,6 +178,7 @@ dependencies:
177
178
  - - ">="
178
179
  - !ruby/object:Gem::Version
179
180
  version: '0'
181
+ description:
180
182
  email: github.60k5k@simplelogin.co
181
183
  executables: []
182
184
  extensions: []
@@ -185,6 +187,7 @@ files:
185
187
  - LICENSE
186
188
  - README.md
187
189
  - lib/activejob-status.rb
190
+ - lib/activejob-status/batch.rb
188
191
  - lib/activejob-status/progress.rb
189
192
  - lib/activejob-status/status.rb
190
193
  - lib/activejob-status/storage.rb
@@ -194,6 +197,7 @@ homepage: https://github.com/inkstak/activejob-status
194
197
  licenses:
195
198
  - MIT
196
199
  metadata: {}
200
+ post_install_message:
197
201
  rdoc_options: []
198
202
  require_paths:
199
203
  - lib
@@ -204,11 +208,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
208
  version: '0'
205
209
  required_rubygems_version: !ruby/object:Gem::Requirement
206
210
  requirements:
207
- - - ">="
211
+ - - ">"
208
212
  - !ruby/object:Gem::Version
209
- version: '0'
213
+ version: 1.3.1
210
214
  requirements: []
211
- rubygems_version: 3.6.0.dev
215
+ rubygems_version: 3.4.6
216
+ signing_key:
212
217
  specification_version: 4
213
218
  summary: Monitor your jobs
214
219
  test_files: []