intercom-rails 0.2.19 → 0.2.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ module IntercomRails
15
15
  new(*args).run
16
16
  end
17
17
 
18
- attr_reader :uri, :http
18
+ attr_reader :uri, :http, :max_batch_size
19
19
  attr_accessor :failed, :total_sent
20
20
 
21
21
  def initialize(options = {})
@@ -23,6 +23,7 @@ module IntercomRails
23
23
  @http = Net::HTTP.new(@uri.host, @uri.port)
24
24
  @failed = []
25
25
  @total_sent = 0
26
+ @max_batch_size = [(options[:max_batch_size] || 100), 100].min
26
27
 
27
28
  @status_enabled = !!options[:status_enabled]
28
29
 
@@ -58,7 +59,7 @@ module IntercomRails
58
59
  def run
59
60
  assert_runnable
60
61
 
61
- info "Sending users in batches of #{MAX_BATCH_SIZE}:"
62
+ info "Sending users in batches of #{max_batch_size}:"
62
63
  batches do |batch, number_in_batch|
63
64
  failures = send_users(batch)['failed']
64
65
  self.failed += failures
@@ -78,17 +79,17 @@ module IntercomRails
78
79
  end
79
80
 
80
81
  private
81
- MAX_BATCH_SIZE = 100
82
+
82
83
  def batches
83
84
  if active_record?(user_klass)
84
- user_klass.find_in_batches(:batch_size => MAX_BATCH_SIZE) do |users|
85
+ user_klass.find_in_batches(:batch_size => max_batch_size) do |users|
85
86
  users_for_wire = map_to_users_for_wire(users)
86
87
 
87
88
  yield(prepare_batch(users_for_wire), users_for_wire.count) unless users_for_wire.count.zero?
88
89
  end
89
90
  elsif mongoid?(user_klass)
90
- 0.step(user_klass.all.count, MAX_BATCH_SIZE) do |offset|
91
- users_for_wire = map_to_users_for_wire(user_klass.limit(MAX_BATCH_SIZE).skip(offset))
91
+ 0.step(user_klass.all.count, max_batch_size) do |offset|
92
+ users_for_wire = map_to_users_for_wire(user_klass.limit(max_batch_size).skip(offset))
92
93
  yield(prepare_batch(users_for_wire), users_for_wire.count) unless users_for_wire.count.zero?
93
94
  end
94
95
  end
@@ -145,7 +146,7 @@ module IntercomRails
145
146
 
146
147
  return response if successful_response?(response)
147
148
  perform_request(request, attempts + 1, :failed_response => response)
148
- rescue Timeout::Error, Errno::ECONNREFUSED => e
149
+ rescue Timeout::Error, Errno::ECONNREFUSED, EOFError => e
149
150
  perform_request(request, attempts + 1, :exception => e)
150
151
  end
151
152
 
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.2.19"
2
+ VERSION = "0.2.20"
3
3
  end
@@ -107,4 +107,19 @@ class ImportUnitTest < MiniTest::Unit::TestCase
107
107
  User.rspec_reset
108
108
  end
109
109
 
110
+ def test_max_batch_size_default
111
+ @import = IntercomRails::Import.new
112
+ assert_equal 100, @import.max_batch_size
113
+ end
114
+
115
+ def test_max_batch_size_settable
116
+ @import = IntercomRails::Import.new(:max_batch_size => 50)
117
+ assert_equal 50, @import.max_batch_size
118
+ end
119
+
120
+ def test_max_batch_size_hard_limit
121
+ @import = IntercomRails::Import.new(:max_batch_size => 101)
122
+ assert_equal 100, @import.max_batch_size
123
+ end
124
+
110
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: