hekenga 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/hekenga/document_task.rb +2 -1
- data/lib/hekenga/document_task_executor.rb +30 -4
- data/lib/hekenga/dsl/document_task.rb +4 -0
- data/lib/hekenga/scaffold.rb +6 -2
- data/lib/hekenga/version.rb +1 -1
- 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: 94824a7ff42ed31e87c54b5093ad9b8a03b27b08ec5cc7c4f45491b71b3dcc79
|
4
|
+
data.tar.gz: ca0ffaded81560273fa6421de3dfdb9a0efce0fd62f95c410bd31004cb17a816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8677a4cd8023f511971b54ac4458e7b230ee693246473d77b9e3237895ef95670aa157d0117f13223a0df4dde71430de9c940bfc89315422203e23ec3434218e
|
7
|
+
data.tar.gz: 69b879e26c4d7771377881d9e83d411fa3b0a2674ce851b5b9b74f323c1c2dec749218257766b27e467eb409708f221d9125a8451bd9d394b103e654e86785da
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v1.1.0
|
4
|
+
|
5
|
+
- `setup` is now passed the current batch of documents so it can be used to
|
6
|
+
preload effectively
|
7
|
+
- `after` has been added - this is a block of code that will be passed the
|
8
|
+
current batch of written documents after a write has been completed. If
|
9
|
+
no documents were written, this block will not be called
|
10
|
+
|
11
|
+
## v1.0.4
|
12
|
+
|
13
|
+
- Log errors during document tasks to stdout
|
14
|
+
|
3
15
|
## v1.0.3
|
4
16
|
|
5
17
|
- Fix `timeless!` being ignored
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'hekenga/irreversible'
|
2
2
|
module Hekenga
|
3
3
|
class DocumentTask
|
4
|
-
attr_reader :ups, :downs, :setups, :filters
|
4
|
+
attr_reader :ups, :downs, :setups, :filters, :after_callbacks
|
5
5
|
attr_accessor :parallel, :scope, :timeless, :batch_size
|
6
6
|
attr_accessor :description, :invalid_strategy, :skip_prepare, :write_strategy
|
7
7
|
attr_accessor :always_write, :use_transaction
|
@@ -11,6 +11,7 @@ module Hekenga
|
|
11
11
|
@downs = []
|
12
12
|
@setups = []
|
13
13
|
@filters = []
|
14
|
+
@after_callbacks = []
|
14
15
|
@invalid_strategy = :continue
|
15
16
|
@write_strategy = :update
|
16
17
|
@skip_prepare = false
|
@@ -13,6 +13,7 @@ module Hekenga
|
|
13
13
|
@skipped_records = []
|
14
14
|
@failed_records = []
|
15
15
|
@backed_up_records = {}
|
16
|
+
@seen_errors = []
|
16
17
|
end
|
17
18
|
|
18
19
|
def run!
|
@@ -27,6 +28,7 @@ module Hekenga
|
|
27
28
|
# In test mode, the transaction will be aborted - so we need to write
|
28
29
|
# the result outside of the run! block
|
29
30
|
write_result if task_record.test_mode
|
31
|
+
after_callback
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -48,7 +50,9 @@ module Hekenga
|
|
48
50
|
|
49
51
|
delegate :task_idx, to: :task_record
|
50
52
|
|
51
|
-
attr_reader :migrated_records, :records_to_write, :filtered_records,
|
53
|
+
attr_reader :migrated_records, :records_to_write, :filtered_records,
|
54
|
+
:invalid_records, :skipped_records, :failed_records, :backed_up_records,
|
55
|
+
:seen_errors
|
52
56
|
|
53
57
|
def migration_complete?
|
54
58
|
migration.task_records(task_idx).incomplete.none?
|
@@ -84,7 +88,8 @@ module Hekenga
|
|
84
88
|
else
|
85
89
|
skipped_records << record
|
86
90
|
end
|
87
|
-
rescue =>
|
91
|
+
rescue => e
|
92
|
+
print_error(e)
|
88
93
|
failed_records << record
|
89
94
|
end
|
90
95
|
end
|
@@ -94,7 +99,8 @@ module Hekenga
|
|
94
99
|
backup_record(record)
|
95
100
|
task.up!(@context, record)
|
96
101
|
migrated_records << record
|
97
|
-
rescue =>
|
102
|
+
rescue => e
|
103
|
+
print_error(e)
|
98
104
|
failed_records << record
|
99
105
|
end
|
100
106
|
end
|
@@ -201,7 +207,7 @@ module Hekenga
|
|
201
207
|
@context = Hekenga::Context.new(test_mode: task_record.test_mode)
|
202
208
|
begin
|
203
209
|
task.setups&.each do |setup|
|
204
|
-
@context.instance_exec(&setup)
|
210
|
+
@context.instance_exec(records, &setup)
|
205
211
|
end
|
206
212
|
rescue => e
|
207
213
|
fail_and_cancel!(e)
|
@@ -212,6 +218,18 @@ module Hekenga
|
|
212
218
|
@context = nil
|
213
219
|
end
|
214
220
|
|
221
|
+
def after_callback
|
222
|
+
return if records_to_write.empty?
|
223
|
+
|
224
|
+
task.after_callbacks&.each do |callback|
|
225
|
+
@context.instance_exec(records_to_write, &callback)
|
226
|
+
end
|
227
|
+
rescue => e
|
228
|
+
# Error is just printed for now as we've already migrated, don't
|
229
|
+
# want to overwrite the task record state
|
230
|
+
print_error(e)
|
231
|
+
end
|
232
|
+
|
215
233
|
def fail_and_cancel!(error)
|
216
234
|
log = migration.log(task_idx)
|
217
235
|
log.add_failure({
|
@@ -268,5 +286,13 @@ module Hekenga
|
|
268
286
|
def task
|
269
287
|
@task ||= migration.tasks[task_idx]
|
270
288
|
end
|
289
|
+
|
290
|
+
def print_error(error)
|
291
|
+
message = [error.message, error.backtrace].join("\n")
|
292
|
+
return if seen_errors.include?(message.hash)
|
293
|
+
|
294
|
+
seen_errors << message.hash
|
295
|
+
Hekenga.log(message)
|
296
|
+
end
|
271
297
|
end
|
272
298
|
end
|
data/lib/hekenga/scaffold.rb
CHANGED
@@ -50,8 +50,8 @@ module Hekenga
|
|
50
50
|
# #write_strategy :update # :delete_then_insert
|
51
51
|
#
|
52
52
|
# # Called once per batch, instance variables will be accessible
|
53
|
-
# # in the filter
|
54
|
-
# #setup do
|
53
|
+
# # in the filter, up and after blocks
|
54
|
+
# #setup do |docs|
|
55
55
|
# #end
|
56
56
|
#
|
57
57
|
# #filter do |doc|
|
@@ -59,6 +59,10 @@ module Hekenga
|
|
59
59
|
#
|
60
60
|
# up do |doc|
|
61
61
|
# end
|
62
|
+
#
|
63
|
+
# # Called once per batch passing successfully written records
|
64
|
+
# #after do |docs|
|
65
|
+
# #end
|
62
66
|
#end
|
63
67
|
end
|
64
68
|
EOF
|
data/lib/hekenga/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hekenga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tapio Saarinen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|