active_touch 1.5.0 → 2.0.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mjk4NzRlMTYzZDJlNDdjMmQwYzY3MmM3NWIyNzUwYjc1MDk0NjM4Zg==
4
+ ZWI0YWQ1MmY3YjNjZDJlNzY1OWY5MmQ3OTI5Y2YxNGMwZGZkYWZmNQ==
5
5
  data.tar.gz: !binary |-
6
- ODliZDdhNmJhYmZkMDMwMmU0YjJmYjk4YzU3M2JkYjMyMTllNGMwYw==
6
+ ZWVjYzRkYTc2NjQyNmY0NTI3MDJlZmZhZmFkZmZkNzM2OGEwNGQ5Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzcwOTk2ODhiOWI3ZWRiN2NkODNjYTI1ZGRmZTg4Njg3MDBmOTc3ZDM4MDky
10
- YWZlZmIzODVkM2JiOTg0OTIxYTQyYTk1NjBiOTkwM2U2M2E5ODg0MDY5MWY5
11
- ZGQxN2I1NzVkYWJhYTcwZjkzZDMxYjVlYTAwMmFlMDg1NGM4MjM=
9
+ M2E2ZWVmNzc2MzFiMTA2MWE4ZjY0MTBhZTJjYjE0ZDk5ZGVjMzk4YjEyNmI2
10
+ N2Q3ZGFmN2I3OGNlZTFkMTc3ZDAwYjNlYWJlNGJlNjRkMGYzMjcyOGQyZmYx
11
+ MDUzMzkzOGJkNWJkZGM1ZDg5OTIzZDBmOGEyNWQ1N2UyYTQxYzc=
12
12
  data.tar.gz: !binary |-
13
- NDgxMjNjYTYzMTJlZTgxNDY3M2EzNDhmMmVhYzIzOTAyMTgzZTRhZjAyMzY2
14
- OTNiMGFlZDRmZjcyNzA2OWJmMjEyZDg5ZjQ2MjJlN2MwOTA5MmRhYmIwMmI2
15
- ZDRmZDQzZTIyNGM1ZGMxNDk2OTUwZjIwMzUyODRhNzAzZjVjNTU=
13
+ MTNmOWIyZDM2MTQyMGY0ODEwMjRlM2M1OTU1Y2E1NTI4ZTZiOGQyNDU3MmNj
14
+ YTI3MjJjMmFmZmI4NjE1ZDkxOWVlMTIwOTY5MzExMmRjYjk2MjFmYzhlZmJk
15
+ Y2M2OTllZGEwMTkzYmExODJhYzIyNWM3ZmViOGE4MTc5OWVlM2Q=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_touch (1.4.4)
4
+ active_touch (2.0.0)
5
5
  rails (~> 4.2)
6
6
 
7
7
  GEM
@@ -13,13 +13,17 @@ module ActiveTouch
13
13
  end
14
14
 
15
15
  class Configuration
16
- attr_accessor :async, :batch_size, :ignored_attributes, :queue
16
+ attr_accessor :associated_touch_delay, :async, :batch_process, :batch_size, :ignored_attributes,
17
+ :queue, :touch_process
17
18
 
18
19
  def initialize
20
+ @associated_touch_delay = 0
19
21
  @async = false
22
+ @batch_process = true
20
23
  @batch_size = 100
21
24
  @ignored_attributes = [:updated_at]
22
25
  @queue = 'default'
26
+ @touch_process = :batch_synchronous
23
27
  end
24
28
  end
25
29
 
@@ -1,7 +1,7 @@
1
1
  module ActiveTouch
2
2
  class TouchJob < ActiveJob::Base
3
3
 
4
- def perform(record, association, after_touch, is_async = false)
4
+ def perform(record, association, after_touch, is_async = ActiveTouch.configuration.async)
5
5
  associated = association == 'self' ? record : record.send(association)
6
6
 
7
7
  if associated.is_a? ActiveRecord::Base
@@ -10,10 +10,28 @@ module ActiveTouch
10
10
 
11
11
  elsif !associated.nil?
12
12
 
13
- 0.step(associated.count, ActiveTouch.configuration.batch_size).each do |offset|
14
- batch = associated.offset(offset).limit(ActiveTouch.configuration.batch_size)
15
- batch.update_all(updated_at: record.updated_at)
16
- batch.each { |associate| associate.send(after_touch) } unless after_touch.blank?
13
+ case ActiveTouch.configuration.touch_process
14
+
15
+ when :batch_synchronous
16
+ 0.step(associated.count, ActiveTouch.configuration.batch_size).each do |offset|
17
+ batch = associated.offset(offset).limit(ActiveTouch.configuration.batch_size)
18
+ batch.update_all(updated_at: record.updated_at)
19
+ batch.each { |associate| associate.send(after_touch) } unless after_touch.blank?
20
+ end
21
+
22
+ when :non_batch_asynchronous
23
+ associated.each do |associate|
24
+ TouchJob
25
+ .set(
26
+ queue: ActiveTouch.configuration.queue,
27
+ wait: ActiveTouch.configuration.associated_touch_delay.seconds
28
+ )
29
+ .perform_later(associate, 'self', after_touch, is_async)
30
+ end
31
+
32
+ when :non_batch_synchronous
33
+ associated.update_all(updated_at: record.updated_at)
34
+ associated.each { |associate| associate.send(after_touch) } unless after_touch.blank?
17
35
  end
18
36
  end
19
37
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveTouch
2
- VERSION = '1.5.0'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -3,6 +3,10 @@ ActiveTouch.configure do |config|
3
3
  # Default is false
4
4
  # config.async = false
5
5
 
6
+ # Enable batch processing for large groups of records
7
+ # Default is false
8
+ # config.batch_processing = false
9
+
6
10
  # Batch size of records to touch at a time
7
11
  # Default is 100
8
12
  # config.batch_size = 100
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_touch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Pheasey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-30 00:00:00.000000000 Z
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler