batches_task_processor 0.3.3 → 0.3.6

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: 35e87c4ae1e2728db3bf365e2bb9ceb74aa7d5605bc5fbf5a94aea4fd9559637
4
- data.tar.gz: 65da53cfe48a3aedc8eece776e3100edb5d4d1e29a2b0b99123a6f50f0aa5ee2
3
+ metadata.gz: 1c894648bfdda3e00af8f84664db6b9bc93c9841b75db626b1b7246a5bd122f7
4
+ data.tar.gz: 40730cbc8b5009f5889c823fb7f62ce9fad74667c1a995bdeb9640bc2423cbd3
5
5
  SHA512:
6
- metadata.gz: 6c2a0f73cd1385dba738cc8a09c2159889f067d9e9743f33bae49feb4085c41b49293599b70241a31bdc9612c52e26a31568a56f69ef51b428a9855df7ed3f60
7
- data.tar.gz: bc945ab30a45c47d0519380cd85efd5c15534c7ba5eb1915deed65777ce3e88aa95910311fbdc64d1e7623e085d6c1857bd305e6261f6effc24e5ee367dd2887
6
+ metadata.gz: f470bd0a5de883797fff0cde140f87ab9b61142a148945dad289b47769ed51b213ead81f72c8998cdb7b928b0937a34b892050618c4cf7a175a42afa559049bb
7
+ data.tar.gz: 9fc74754e669dbba709ab01b156b6e2bba1fa59c2edfb989438791a1f2ec11ca4f1a04ab90a36025051ed281a697810f4b7b47bbc59505d5682df86341bc815e
@@ -4,7 +4,7 @@ require 'csv'
4
4
  module BatchesTaskProcessor
5
5
  class Model < ActiveRecord::Base
6
6
  self.table_name = 'batches_task_processors'
7
- has_many :items, class_name: 'BatchesTaskProcessor::ModelItem', dependent: :destroy, foreign_key: :batches_task_processors_id
7
+ has_many :items, class_name: 'BatchesTaskProcessor::ModelItem', dependent: :delete_all, foreign_key: :batches_task_processors_id
8
8
  validates :process_item, presence: true
9
9
  validates :key, presence: true
10
10
  before_save :apply_data_uniqueness
@@ -38,11 +38,16 @@ module BatchesTaskProcessor
38
38
  end
39
39
 
40
40
  def status
41
- Rails.logger.info "Process status: #{task_model.items.count}/#{task_model.data.count}"
41
+ Rails.logger.info "Process status: #{items.count}/#{data.count}"
42
+ end
43
+
44
+ def retry_failures
45
+ start!
42
46
  end
43
47
 
44
48
  def export
45
- path = Rails.root.join('tmp/batches_task_processor_result.csv')
49
+ filename = (key || 'batches_task_processor_result').try(:parameterize)
50
+ path = Rails.root.join("tmp/#{filename}.csv")
46
51
  data = items.pluck(:key, :result, :error_details)
47
52
  data = [['Key', 'Result', 'Error details']] + data
48
53
  File.write(path, data.map(&:to_csv).join)
@@ -55,7 +55,7 @@ module BatchesTaskProcessor
55
55
  (items.try(:find_each) || items.each).with_index(1) do |item, index|
56
56
  key = item.try(:id) || item
57
57
  break log('Process cancelled') if process_cancelled?
58
- next log("Skipping #{key}...") if already_processed?(key)
58
+ next if already_processed?(key)
59
59
 
60
60
  start_process_item(item, job, key, index)
61
61
  end
@@ -72,18 +72,19 @@ module BatchesTaskProcessor
72
72
  def start_process_item(item, job, key, index)
73
73
  log "Processing key: #{key}, job: #{job}, counter: #{index}/#{task_model.qty_items_job}"
74
74
  result = process_item(item)
75
- task_model.items.create!(key: key, result: result.to_s[0..255])
75
+ task_model.items.where(key: key).first_or_initialize.update!(result: result, error_details: nil)
76
76
  rescue => e
77
- task_model.items.create!(key: key, error_details: e.message)
77
+ task_model.items.where(key: key).first_or_initialize.update!(result: nil, error_details: e.message)
78
78
  log "Process failed #{job}/#{key}: #{e.message}"
79
79
  end
80
80
 
81
81
  def already_processed?(key)
82
- task_model.items.where(key: key).exists?
82
+ task_model.items.where(key: key, error_details: nil).exists?
83
83
  end
84
84
 
85
85
  def process_cancelled?
86
- task_model.state == 'cancelled'
86
+ state = BatchesTaskProcessor::Model.select(:state).find(task_model.id).state
87
+ state == 'cancelled'
87
88
  end
88
89
 
89
90
  def log(msg)
@@ -1,3 +1,3 @@
1
1
  module BatchesTaskProcessor
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -18,7 +18,7 @@ class AddBatchesTaskProcessor < ActiveRecord::Migration[5.0]
18
18
  create_table :batches_task_processor_items do |t|
19
19
  t.belongs_to :batches_task_processors, foreign_key: true, index: { name: 'index_batches_task_processors_parent_id' }
20
20
  t.string :key
21
- t.text :result
21
+ t.text :result, limit: 999999
22
22
  t.text :error_details
23
23
  t.timestamps
24
24
  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.3
4
+ version: 0.3.6
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-03 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails