hekenga 1.0.4 → 1.1.0

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: 55037feb4349d723dd34938f3eb9aab8431bad7f287081b685705c6a6d40b046
4
- data.tar.gz: 896bdc203b3f30c543a4f7265bdea16e128d64ed59456e32cecb683a789f684c
3
+ metadata.gz: 94824a7ff42ed31e87c54b5093ad9b8a03b27b08ec5cc7c4f45491b71b3dcc79
4
+ data.tar.gz: ca0ffaded81560273fa6421de3dfdb9a0efce0fd62f95c410bd31004cb17a816
5
5
  SHA512:
6
- metadata.gz: 69a634184500d3c5cca3298a3793c0e5f496d31f935af6265840e1ab7e576de9bc06623cff8c03738fed9f2028146d460fd7ed04cd71e3f684c890a792d6986e
7
- data.tar.gz: 2b916adfaa97a95fa645cd6442aefacd5125f78c2b62ff1b13bfa237e373998ecd44f0c88bdc0b7a239afa9e8f25e2bfb2cc05a4de11f142898c42ce963f246c
6
+ metadata.gz: 8677a4cd8023f511971b54ac4458e7b230ee693246473d77b9e3237895ef95670aa157d0117f13223a0df4dde71430de9c940bfc89315422203e23ec3434218e
7
+ data.tar.gz: 69b879e26c4d7771377881d9e83d411fa3b0a2674ce851b5b9b74f323c1c2dec749218257766b27e467eb409708f221d9125a8451bd9d394b103e654e86785da
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## v1.0.4
4
12
 
5
13
  - Log errors during document tasks to stdout
@@ -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
@@ -28,6 +28,7 @@ module Hekenga
28
28
  # In test mode, the transaction will be aborted - so we need to write
29
29
  # the result outside of the run! block
30
30
  write_result if task_record.test_mode
31
+ after_callback
31
32
  end
32
33
  end
33
34
 
@@ -206,7 +207,7 @@ module Hekenga
206
207
  @context = Hekenga::Context.new(test_mode: task_record.test_mode)
207
208
  begin
208
209
  task.setups&.each do |setup|
209
- @context.instance_exec(&setup)
210
+ @context.instance_exec(records, &setup)
210
211
  end
211
212
  rescue => e
212
213
  fail_and_cancel!(e)
@@ -217,6 +218,18 @@ module Hekenga
217
218
  @context = nil
218
219
  end
219
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
+
220
233
  def fail_and_cancel!(error)
221
234
  log = migration.log(task_idx)
222
235
  log.add_failure({
@@ -67,6 +67,10 @@ module Hekenga
67
67
  def down(&block)
68
68
  @object.downs.push block
69
69
  end
70
+
71
+ def after(&block)
72
+ @object.after_callbacks.push block
73
+ end
70
74
  end
71
75
  end
72
76
  end
@@ -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 & up blocks
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
@@ -1,3 +1,3 @@
1
1
  module Hekenga
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
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
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: 2023-11-06 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler