restforce-db 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/restforce/db/command.rb +8 -1
- data/lib/restforce/db/configuration.rb +23 -0
- data/lib/restforce/db/version.rb +1 -1
- data/lib/restforce/db.rb +9 -8
- data/test/lib/restforce/db/configuration_test.rb +33 -0
- data/test/lib/restforce/db_test.rb +0 -14
- metadata +1 -2
- data/.travis.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2214ab04231e0cbbc83e59248f3f3ec794c01c4
|
4
|
+
data.tar.gz: 560a485242bce00d2b9d219c8775c6854736bb59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbde0d9e95daf9e7eace6492aa9fb3a552bc766c807b34db2ea24ef369b8471651784244b767024db2b8d3e1f904b4e2d3cb4325d85b8a6c325515a0233fbf87
|
7
|
+
data.tar.gz: 928e76319b07d113d6d551a4128307ed4d63bc77c3fcf104201fff6fe2aa25167fbd49f508640ae166b97ae4d1e464718ccff23948eafd63a92353626dc584db
|
data/README.md
CHANGED
@@ -224,6 +224,18 @@ For additional information and a full set of options, you can run:
|
|
224
224
|
|
225
225
|
$ bundle exec bin/restforce-db -h
|
226
226
|
|
227
|
+
#### Configuring the daemon's runtime environment
|
228
|
+
|
229
|
+
Restforce::DB allows you to configure up a block of code which will execute when the daemon process forks. In an initializer (or any other piece of code which will run as your application spins up), you can use `config.after_fork` to set up this hook:
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
Restforce::DB.configure do |config|
|
233
|
+
config.after_fork { ActiveRecord::Base.logger = nil }
|
234
|
+
end
|
235
|
+
```
|
236
|
+
|
237
|
+
The example above would disable the default ActiveRecord logging specifically for activity triggered by the Restforce::DB daemon.
|
238
|
+
|
227
239
|
## System Caveats
|
228
240
|
|
229
241
|
- **API Usage.**
|
data/lib/restforce/db/command.rb
CHANGED
@@ -56,9 +56,16 @@ module Restforce
|
|
56
56
|
def run(options = {})
|
57
57
|
Dir.chdir(Rails.root)
|
58
58
|
|
59
|
-
Restforce::DB::Worker.after_fork
|
60
59
|
Restforce::DB.logger = logger
|
61
60
|
|
61
|
+
# This hook comes from the FileDaemon module, and keeps file descriptors
|
62
|
+
# opened after the process forks.
|
63
|
+
Restforce::DB::Worker.after_fork
|
64
|
+
|
65
|
+
# This hook can be configured in an initializer, and allows changes to
|
66
|
+
# the runtime environment after the process forks.
|
67
|
+
Restforce::DB.after_fork
|
68
|
+
|
62
69
|
worker = Restforce::DB::Worker.new(options)
|
63
70
|
worker.logger = logger
|
64
71
|
worker.tracker = tracker
|
@@ -18,8 +18,31 @@ module Restforce
|
|
18
18
|
client_secret
|
19
19
|
host
|
20
20
|
api_version
|
21
|
+
logger
|
21
22
|
))
|
22
23
|
|
24
|
+
# Public: Allow an after_fork callback to be configured or run. Runs the
|
25
|
+
# previously-configured block if called without arguments.
|
26
|
+
#
|
27
|
+
# block - A block of code to execute after process forking.
|
28
|
+
#
|
29
|
+
# Returns nothing.
|
30
|
+
def after_fork(&block)
|
31
|
+
if block_given?
|
32
|
+
@after_fork ||= block
|
33
|
+
else
|
34
|
+
@after_fork.call if @after_fork
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Public: Get the configured logger. Returns a null logger if no logger
|
39
|
+
# has been configured yet.
|
40
|
+
#
|
41
|
+
# Returns a Logger.
|
42
|
+
def logger
|
43
|
+
@logger ||= Logger.new("/dev/null")
|
44
|
+
end
|
45
|
+
|
23
46
|
# Public: Parse a supplied YAML file for a set of credentials, and use
|
24
47
|
# them to populate the attributes on this configuraton object.
|
25
48
|
#
|
data/lib/restforce/db/version.rb
CHANGED
data/lib/restforce/db.rb
CHANGED
@@ -57,7 +57,15 @@ module Restforce
|
|
57
57
|
class << self
|
58
58
|
|
59
59
|
attr_accessor :last_run
|
60
|
-
attr_writer :configuration
|
60
|
+
attr_writer :configuration
|
61
|
+
|
62
|
+
extend Forwardable
|
63
|
+
def_delegators(
|
64
|
+
:configuration,
|
65
|
+
:logger,
|
66
|
+
:logger=,
|
67
|
+
:after_fork,
|
68
|
+
)
|
61
69
|
|
62
70
|
end
|
63
71
|
|
@@ -68,13 +76,6 @@ module Restforce
|
|
68
76
|
@configuration ||= Configuration.new
|
69
77
|
end
|
70
78
|
|
71
|
-
# Public: Get the current logger for Restforce::DB.
|
72
|
-
#
|
73
|
-
# Returns a Logger instance.
|
74
|
-
def self.logger
|
75
|
-
@logger ||= Logger.new("/dev/null")
|
76
|
-
end
|
77
|
-
|
78
79
|
# Public: Get a Restforce client based on the currently configured settings.
|
79
80
|
#
|
80
81
|
# Returns a Restforce::Data::Client instance.
|
@@ -8,6 +8,39 @@ describe Restforce::DB::Configuration do
|
|
8
8
|
let(:secrets_file) { File.expand_path("../../../../config/secrets.yml", __FILE__) }
|
9
9
|
let(:configuration) { Restforce::DB::Configuration.new }
|
10
10
|
|
11
|
+
describe "#after_fork" do
|
12
|
+
|
13
|
+
it "does nothing if invoked without a block" do
|
14
|
+
# NOTE: We're asserting that this invocation doesn't raise an error.
|
15
|
+
configuration.after_fork
|
16
|
+
end
|
17
|
+
|
18
|
+
it "does not invoke the block on configuration" do
|
19
|
+
a = 1
|
20
|
+
|
21
|
+
configuration.after_fork { a += 1 }
|
22
|
+
|
23
|
+
expect(a).to_equal 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "invokes the configured block when called without arguments" do
|
27
|
+
a = 1
|
28
|
+
|
29
|
+
configuration.after_fork { a += 1 }
|
30
|
+
configuration.after_fork
|
31
|
+
|
32
|
+
expect(a).to_equal 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#logger" do
|
37
|
+
|
38
|
+
it "defaults to a null logger" do
|
39
|
+
log_device = configuration.logger.instance_variable_get("@logdev")
|
40
|
+
expect(log_device.dev.path).to_equal "/dev/null"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
11
44
|
describe "#load" do
|
12
45
|
|
13
46
|
describe "when all configurations are supplied" do
|
@@ -4,20 +4,6 @@ describe Restforce::DB do
|
|
4
4
|
|
5
5
|
configure!
|
6
6
|
|
7
|
-
describe "#logger" do
|
8
|
-
|
9
|
-
it "defaults to a null logger" do
|
10
|
-
log_device = Restforce::DB.logger.instance_variable_get("@logdev")
|
11
|
-
expect(log_device.dev.path).to_equal "/dev/null"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "allows assignment of a new logger" do
|
15
|
-
logger = Logger.new("/dev/null")
|
16
|
-
Restforce::DB.logger = logger
|
17
|
-
expect(Restforce::DB.logger).to_equal logger
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
7
|
describe "#configure" do
|
22
8
|
|
23
9
|
it "yields a Configuration" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restforce-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
@@ -193,7 +193,6 @@ files:
|
|
193
193
|
- ".gitignore"
|
194
194
|
- ".rubocop.yml"
|
195
195
|
- ".rubocop/custom/method_documentation.rb"
|
196
|
-
- ".travis.yml"
|
197
196
|
- Gemfile
|
198
197
|
- LICENSE.txt
|
199
198
|
- README.md
|
data/.travis.yml
DELETED