worker_tools 1.3 → 1.3.1
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 +19 -0
- data/lib/worker_tools/basics.rb +3 -1
- data/lib/worker_tools/csv_input.rb +10 -0
- data/lib/worker_tools/errors.rb +6 -0
- data/lib/worker_tools/version.rb +1 -1
- data/lib/worker_tools/xlsx_input.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 36547805fb8cfbbf750b84c31fb325a918c54501830bbdfd68f8f2c8f5b1267e
|
|
4
|
+
data.tar.gz: 47361b96ca6e8964b688b0ea50e426c2786edc9b0415984fc9dd4c5247c9cc1d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0fbe8c88c4aa16ea93840bae76823d43aa98539110ba3f347607ca809ddf0ae5687a84608d86b73ae3b771816ad746d9e2006c681192fca3c1bec33c04a9af6
|
|
7
|
+
data.tar.gz: c0bbd1d018d2d77a61fd538c337423d6380ed1a351e8844eb930e6fd416068461df06fa8732527cadd5949348be44f3ec70bf6ac97dcfdb1b7eec02825dfd0e2
|
data/README.md
CHANGED
|
@@ -84,6 +84,7 @@ class Import < ApplicationRecord
|
|
|
84
84
|
complete_with_warnings
|
|
85
85
|
failed
|
|
86
86
|
running
|
|
87
|
+
empty
|
|
87
88
|
].map { |e| [e, e] }.to_h
|
|
88
89
|
|
|
89
90
|
enum kind: { foo: 0, bar: 1 }
|
|
@@ -99,6 +100,8 @@ The state `complete` and `failed` are used by the modules. Both `state` and `kin
|
|
|
99
100
|
|
|
100
101
|
The state `complete_with_warnings` indicates that the model contains notes that did not lead to a failure but should get some attention. By default those levels are `warning` and `errors` and can be customized.
|
|
101
102
|
|
|
103
|
+
The state `empty` is automatically set by the CSV and XLSX input modules when the input file does not exist or is empty (0 bytes).
|
|
104
|
+
|
|
102
105
|
In this case the migration would be something like this:
|
|
103
106
|
|
|
104
107
|
```ruby
|
|
@@ -199,6 +202,22 @@ See all methods in [slack_error_notifier](/lib/worker_tools/slack_error_notifier
|
|
|
199
202
|
|
|
200
203
|
See all methods in [csv_input](/lib/worker_tools/csv_input.rb)
|
|
201
204
|
|
|
205
|
+
### Skipping File Presence Check
|
|
206
|
+
|
|
207
|
+
By default, the CSV Input module checks if the file exists and is not empty. If you need to skip this validation (for example, if an empty file is valid for your process), you can override the `csv_input_file_presence_check` method:
|
|
208
|
+
|
|
209
|
+
```ruby
|
|
210
|
+
class CsvInputExample
|
|
211
|
+
include WorkerTools::CsvInput
|
|
212
|
+
|
|
213
|
+
def csv_input_file_presence_check
|
|
214
|
+
true
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# ... rest of your implementation
|
|
218
|
+
end
|
|
219
|
+
```
|
|
220
|
+
|
|
202
221
|
## Module CSV Output
|
|
203
222
|
|
|
204
223
|
See all methods in [csv_output](/lib/worker_tools/csv_output.rb)
|
data/lib/worker_tools/basics.rb
CHANGED
|
@@ -57,7 +57,9 @@ module WorkerTools
|
|
|
57
57
|
# rubocop:disable Lint/RescueException
|
|
58
58
|
rescue Exception => e
|
|
59
59
|
# rubocop:enable Lint/RescueException
|
|
60
|
-
|
|
60
|
+
state = e.is_a?(WorkerTools::Errors::EmptyFile) ? 'empty' : 'failed'
|
|
61
|
+
save_state_without_validate(state)
|
|
62
|
+
|
|
61
63
|
raise unless silent_error?(e)
|
|
62
64
|
end
|
|
63
65
|
|
|
@@ -59,6 +59,8 @@ module WorkerTools
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def csv_input_columns_array_check(csv_rows_enum)
|
|
62
|
+
return if csv_rows_enum.first.nil?
|
|
63
|
+
|
|
62
64
|
expected_columns_length = csv_input_columns.length
|
|
63
65
|
actual_columns_length = csv_rows_enum.first.length
|
|
64
66
|
return if expected_columns_length == actual_columns_length
|
|
@@ -68,6 +70,8 @@ module WorkerTools
|
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
def csv_input_columns_hash_check(csv_rows_enum)
|
|
73
|
+
raise Errors::MissingColumns, 'The headers are missing' if csv_rows_enum.first.nil?
|
|
74
|
+
|
|
71
75
|
expected_names = csv_input_columns.values
|
|
72
76
|
filtered_actual_names = csv_rows_enum.first.map { |n| csv_input_header_normalized(n) }
|
|
73
77
|
csv_input_columns_hash_check_duplicates(filtered_actual_names)
|
|
@@ -145,8 +149,14 @@ module WorkerTools
|
|
|
145
149
|
true
|
|
146
150
|
end
|
|
147
151
|
|
|
152
|
+
def csv_input_file_presence_check
|
|
153
|
+
raise Errors::EmptyFile, 'The file does not exist' unless File.exist?(csv_input_file_path)
|
|
154
|
+
raise Errors::EmptyFile, 'The file is empty' if File.zero?(csv_input_file_path)
|
|
155
|
+
end
|
|
156
|
+
|
|
148
157
|
def csv_input_foreach
|
|
149
158
|
@csv_input_foreach ||= begin
|
|
159
|
+
csv_input_file_presence_check
|
|
150
160
|
csv_input_columns_check(csv_rows_enum)
|
|
151
161
|
|
|
152
162
|
CsvInputForeach.new(
|
data/lib/worker_tools/errors.rb
CHANGED
data/lib/worker_tools/version.rb
CHANGED
|
@@ -142,8 +142,14 @@ module WorkerTools
|
|
|
142
142
|
true
|
|
143
143
|
end
|
|
144
144
|
|
|
145
|
+
def xlsx_input_file_presence_check
|
|
146
|
+
raise Errors::EmptyFile, 'The file does not exist' unless File.exist?(xlsx_input_file_path)
|
|
147
|
+
raise Errors::EmptyFile, 'The file is empty' if File.zero?(xlsx_input_file_path)
|
|
148
|
+
end
|
|
149
|
+
|
|
145
150
|
def xlsx_input_foreach
|
|
146
151
|
@xlsx_input_foreach ||= begin
|
|
152
|
+
xlsx_input_file_presence_check
|
|
147
153
|
xlsx_input_columns_check(xlsx_rows_enum)
|
|
148
154
|
|
|
149
155
|
XlsxInputForeach.new(
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: worker_tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- fsainz
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|