restforce-db 4.0.3 → 4.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/forked_process.rb +3 -1
- data/lib/restforce/db/task_manager.rb +8 -0
- data/lib/restforce/db/version.rb +1 -1
- data/lib/restforce/db/worker.rb +4 -3
- data/lib/restforce/extensions.rb +18 -0
- data/test/lib/forked_process_test.rb +39 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8a5c9eba12dc0b5c61dd46c6f72668d5b0e2328
|
4
|
+
data.tar.gz: a967c9fd3a4940ec403cb6386d7b1b510d6fc666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ae6ffc5111235b6dbd23ab20e78076f6d47478bd706f8b2630b289a29eca449a23bad0d9bbc781fe65e304b5252d8498b1e805ca4d5c7ad579d1e37b7f5b86c
|
7
|
+
data.tar.gz: 1b4e5db790c4bc2d000519b57cc3321a1c34a5332c2858f693616692e548258c168aa076b5a7d3e0d729593477f998ef398145af9c66f8d7895652def7c33264
|
data/lib/forked_process.rb
CHANGED
@@ -4,6 +4,8 @@ require "English"
|
|
4
4
|
# forked process, and relaying its output to another block.
|
5
5
|
class ForkedProcess
|
6
6
|
|
7
|
+
class UnsuccessfulExit < RuntimeError; end
|
8
|
+
|
7
9
|
# Public: Define a callback which will be run in a forked process.
|
8
10
|
#
|
9
11
|
# Yields an IO object opened for writing when `run` is invoked.
|
@@ -39,7 +41,7 @@ class ForkedProcess
|
|
39
41
|
@read_block.call(reader)
|
40
42
|
Process.wait(pid)
|
41
43
|
|
42
|
-
raise
|
44
|
+
raise UnsuccessfulExit unless $CHILD_STATUS.success?
|
43
45
|
end
|
44
46
|
|
45
47
|
end
|
@@ -59,6 +59,11 @@ module Restforce
|
|
59
59
|
|
60
60
|
# Internal: Log a description and response time for a specific named task.
|
61
61
|
#
|
62
|
+
# NOTE: AuthenticationErrors from Restforce's middleware seem to be linked
|
63
|
+
# to thread-safety issues, so we want to error out the entire processing
|
64
|
+
# loop in the event that we run into one of these. This is the reason for
|
65
|
+
# the fairly convoluted `rescue` chain below.
|
66
|
+
#
|
62
67
|
# name - A String task name.
|
63
68
|
# task_class - A Restforce::DB::Task subclass.
|
64
69
|
# mapping - A Restforce::DB::Mapping.
|
@@ -70,6 +75,9 @@ module Restforce
|
|
70
75
|
log format(" FINISHED #{name} after %.4f", runtime)
|
71
76
|
|
72
77
|
true
|
78
|
+
rescue Restforce::AuthenticationError => e
|
79
|
+
error(e)
|
80
|
+
raise e
|
73
81
|
rescue => e
|
74
82
|
error(e)
|
75
83
|
false
|
data/lib/restforce/db/version.rb
CHANGED
data/lib/restforce/db/worker.rb
CHANGED
@@ -127,10 +127,11 @@ module Restforce
|
|
127
127
|
|
128
128
|
begin
|
129
129
|
forked.run
|
130
|
-
rescue => e
|
130
|
+
rescue ForkedProcess::UnsuccessfulExit => e
|
131
131
|
# NOTE: Due to thread-safety issues in any of a number of libraries
|
132
|
-
# included in the host application (even ActiveSupport itself),
|
133
|
-
# forked processes may occasionally encounter
|
132
|
+
# included in the host application (even in ActiveSupport itself),
|
133
|
+
# our forked processes may occasionally encounter various annoying
|
134
|
+
# and intermittent errors.
|
134
135
|
#
|
135
136
|
# Retrying here is our way of handling that. It's not great, but
|
136
137
|
# it's the best we can do for now without sacrificing the benefits
|
data/lib/restforce/extensions.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
module Restforce
|
2
2
|
|
3
|
+
# :nodoc:
|
4
|
+
class Middleware::Authentication < Restforce::Middleware # rubocop:disable Style/ClassAndModuleChildren
|
5
|
+
|
6
|
+
# Internal: Get an error message for the passed response. Overrides the
|
7
|
+
# default behavior of the middleware to correctly handle broken responses
|
8
|
+
# from Faraday.
|
9
|
+
#
|
10
|
+
# Returns a String.
|
11
|
+
def error_message(response)
|
12
|
+
if response.status == 0
|
13
|
+
"Request was closed prematurely"
|
14
|
+
else
|
15
|
+
"#{response.body['error']}: #{response.body['error_description']}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
3
21
|
# :nodoc:
|
4
22
|
class SObject
|
5
23
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
describe ForkedProcess do
|
4
|
+
|
5
|
+
describe "running a forked process" do
|
6
|
+
let(:process) do
|
7
|
+
ForkedProcess.new.tap do |forked|
|
8
|
+
forked.write { |writer| writer.write("Hello!") }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#run" do
|
13
|
+
|
14
|
+
it "synchronizes the `write` block's output into a `read` block" do
|
15
|
+
value = nil
|
16
|
+
|
17
|
+
process.read { |reader| value = reader.read }
|
18
|
+
process.run
|
19
|
+
|
20
|
+
expect(value).to_equal("Hello!")
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "when the write block exits unsuccessfully due to an error" do
|
24
|
+
let(:process) do
|
25
|
+
ForkedProcess.new.tap do |forked|
|
26
|
+
forked.write { |_| raise "Whoops!" }
|
27
|
+
forked.read { |_| nil }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "raises an UnsuccessfulExit exception" do
|
32
|
+
expect { silence_stream(STDERR) { process.run } }.to_raise(
|
33
|
+
ForkedProcess::UnsuccessfulExit,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restforce-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -337,6 +337,7 @@ files:
|
|
337
337
|
- test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_no_associated_database_record/does_nothing_for_this_specific_mapping.yml
|
338
338
|
- test/cassettes/Restforce_DB_Worker/a_race_condition_during_synchronization/does_not_change_the_user-entered_name_on_the_database_record.yml
|
339
339
|
- test/cassettes/Restforce_DB_Worker/a_race_condition_during_synchronization/overrides_the_stale-but-more-recent_name_on_the_Salesforce.yml
|
340
|
+
- test/lib/forked_process_test.rb
|
340
341
|
- test/lib/restforce/db/accumulator_test.rb
|
341
342
|
- test/lib/restforce/db/adapter_test.rb
|
342
343
|
- test/lib/restforce/db/association_cache_test.rb
|