batches_task_processor 0.3.1 → 0.3.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e3ca93ca15247aafcea0afc6873b11bc26d8519e7b5ef477ceefd9174552888
|
4
|
+
data.tar.gz: e2669c5ed9c3f8afdefa0d5e59ee7750437560d95b78792dfa5c43da2edbbf1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 140fa98d409be395a422f2687d64d0690b1b65ae1ded1cd7e00e2b0d3217680c65b8629b7aea8da5b38dd6b62fb79acd8631ae250bfe262121b1107466b65f16
|
7
|
+
data.tar.gz: e594672fb7e890d0e475f7480f6b503c34d64fc4525c50c6bfe47909b1c4b573ab6af62db13140d847cd6a5ce49332e42d7b3ea8db75d5931d27b284dea41b99
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# BatchesTaskProcessor
|
2
|
-
Ruby Gem that allows to process huge amount of any kind of tasks in parallel using batches with the ability to cancel at any time.
|
3
|
-
The jobs created can be processed in background or in the foreground (inline)
|
2
|
+
Ruby Gem that allows to process huge amount of any kind of tasks in parallel using batches with the ability to cancel at any time and rerun later (excludes the already processed ones when rerunning) which reduces the process time dramatically.
|
3
|
+
The jobs created can be processed in background (via background jobs) or in the foreground (inline).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
Add this line to your application's Gemfile:
|
@@ -8,6 +8,7 @@ module BatchesTaskProcessor
|
|
8
8
|
validates :process_item, presence: true
|
9
9
|
validates :key, presence: true
|
10
10
|
before_create :apply_data_uniqueness
|
11
|
+
before_create :check_qty_jobs
|
11
12
|
# state: :pending, :processing, :finished, :canceled
|
12
13
|
|
13
14
|
def qty_items_job
|
@@ -22,6 +23,11 @@ module BatchesTaskProcessor
|
|
22
23
|
items.count == data.count
|
23
24
|
end
|
24
25
|
|
26
|
+
# Text data columns support (Mysql only)
|
27
|
+
def data
|
28
|
+
self[:data].is_a?(String) ? JSON.parse(self[:data] || '[]') : self[:data]
|
29
|
+
end
|
30
|
+
|
25
31
|
# ********* user methods
|
26
32
|
def start!
|
27
33
|
Processor.new(id).call
|
@@ -49,5 +55,10 @@ module BatchesTaskProcessor
|
|
49
55
|
def apply_data_uniqueness
|
50
56
|
self.data = data.uniq
|
51
57
|
end
|
58
|
+
|
59
|
+
# Fix: at least 1 item per job
|
60
|
+
def check_qty_jobs
|
61
|
+
self.qty_jobs = data.count if data.count < qty_jobs
|
62
|
+
end
|
52
63
|
end
|
53
64
|
end
|
@@ -5,7 +5,8 @@ class AddBatchesTaskProcessor < ActiveRecord::Migration[5.0]
|
|
5
5
|
create_table :batches_task_processors do |t|
|
6
6
|
t.string :key
|
7
7
|
t.string :state, default: :pending
|
8
|
-
t.json :data, default: []
|
8
|
+
t.json :data, default: [] if support_json?
|
9
|
+
t.text :data unless support_json?
|
9
10
|
t.integer :qty_jobs, default: 10
|
10
11
|
t.datetime :finished_at
|
11
12
|
t.text :preload_job_items
|
@@ -22,4 +23,10 @@ class AddBatchesTaskProcessor < ActiveRecord::Migration[5.0]
|
|
22
23
|
t.timestamps
|
23
24
|
end
|
24
25
|
end
|
26
|
+
|
27
|
+
def support_json?
|
28
|
+
connector_name = ActiveRecord::Base.connection.adapter_name.downcase
|
29
|
+
no_json = connector_name.include?('mysql') || connector_name.include?('sqlite')
|
30
|
+
!no_json
|
31
|
+
end
|
25
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batches_task_processor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen Peredo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|