batches_task_processor 0.3.1 → 0.3.2

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: 6b83bdfebcd837e7ee632a01502d5796ad29ad096e63486cd4d9513dd5882908
4
- data.tar.gz: a8e2fbfafe6c76ca0ddab0810b24797dbc5ce3b6eceb84f15c2b587078a8d558
3
+ metadata.gz: 9e3ca93ca15247aafcea0afc6873b11bc26d8519e7b5ef477ceefd9174552888
4
+ data.tar.gz: e2669c5ed9c3f8afdefa0d5e59ee7750437560d95b78792dfa5c43da2edbbf1e
5
5
  SHA512:
6
- metadata.gz: a2aca1fb9e37d1c3c7e7af5e51cc593bcbbf1d83f37654bb81f9ef0cc45740a5d33467f3ead66a20f93fedf25f5ac1b81568a49019673ee0f47bf61bf3fd2629
7
- data.tar.gz: 43d671b910781c69ac56bee5c363213c7590c162e5f17cf48882e31ea5dcc20ae7311186b30c5d9b9fdbc037a3e342097543b46d084112477c794057ccc89612
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) with the ability to rerun/retry later (excludes the already processed ones).
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
@@ -1,3 +1,3 @@
1
1
  module BatchesTaskProcessor
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  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.1
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-01 00:00:00.000000000 Z
11
+ date: 2022-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails