restforce-db 2.1.6 → 2.2.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
  SHA1:
3
- metadata.gz: f345da89828f81e0461a71a5e552ead233095c5b
4
- data.tar.gz: 8f4d3d95e22cb4f56eadef22022bd8878c4db60b
3
+ metadata.gz: 71c79dd792a31d0dc8a920302fd0f66d897750ef
4
+ data.tar.gz: 268dab371d9549a15100014c873ba6ee7d603a23
5
5
  SHA512:
6
- metadata.gz: 04321dac381dc1ca4f06a2b625c5f317426422ee8d94fa89382e2a6a76ee07550d3c2ed041464998c72a09f3e9bea7f2e683b13c2c911f3d5bec039f0f6d93d5
7
- data.tar.gz: 96db605dd20e59b25ba5dd2a7725ef26dc7f1a4e3e24de7d030dfa012d3f68c2da39bb8958e7a305124f949273390fb2a85934e07c0c2312bc3636ff70f8244b
6
+ metadata.gz: f92441f1d521bac62ca537d5687f5082717f1ed743b89c10ab271ca3e4aa28b5088597f841c4659bc63568040ebcc16b8382d47e12eee27f46fc2f6e25b6bf35
7
+ data.tar.gz: 7be9676f2c5052325da2fa3c0722edf5bc0c2a5afa549f9d1dc5254396a0f9b368646ac1112f62204a36fba935c2ea71a889377a863cf4f5cec4850e110b66d0
data/README.md CHANGED
@@ -226,11 +226,11 @@ For additional information and a full set of options, you can run:
226
226
 
227
227
  #### Configuring the daemon's runtime environment
228
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:
229
+ Restforce::DB allows you to configure a block of code which will execute before the daemon process's polling loop initiates. In an initializer (or any other piece of code which will run as your application spins up), you can use `config.before` to set up this hook:
230
230
 
231
231
  ```ruby
232
232
  Restforce::DB.configure do |config|
233
- config.after_fork { ActiveRecord::Base.logger = nil }
233
+ config.before { |_worker| ActiveRecord::Base.logger = nil }
234
234
  end
235
235
  ```
236
236
 
@@ -56,20 +56,18 @@ module Restforce
56
56
  def run(options = {})
57
57
  Dir.chdir(Rails.root)
58
58
 
59
- Restforce::DB.logger = logger
60
-
61
59
  # This hook comes from the FileDaemon module, and keeps file descriptors
62
60
  # opened after the process forks.
63
61
  Restforce::DB::Worker.after_fork
64
62
 
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
-
69
63
  worker = Restforce::DB::Worker.new(options)
70
64
  worker.logger = logger
71
65
  worker.tracker = tracker
72
66
 
67
+ # This hook can be configured in an initializer, and allows changes to
68
+ # the worker before the daemon loop begins processing.
69
+ Restforce::DB.before(worker)
70
+
73
71
  worker.start
74
72
  rescue => e
75
73
  logger.fatal e
@@ -21,17 +21,19 @@ module Restforce
21
21
  logger
22
22
  ))
23
23
 
24
- # Public: Allow an after_fork callback to be configured or run. Runs the
25
- # previously-configured block if called without arguments.
24
+ # Public: Allow a `before` callback to be configured or run. Runs the
25
+ # previously-configured block with any passed objects if called without a
26
+ # block.
26
27
  #
28
+ # args - An arbitrary collection of arguments to pass to the hook.
27
29
  # block - A block of code to execute after process forking.
28
30
  #
29
31
  # Returns nothing.
30
- def after_fork(&block)
32
+ def before(*args, &block)
31
33
  if block_given?
32
- @after_fork ||= block
34
+ @before_hook = block
33
35
  else
34
- @after_fork.call if @after_fork
36
+ @before_hook.call(*args) if @before_hook
35
37
  end
36
38
  end
37
39
 
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "2.1.6"
6
+ VERSION = "2.2.0"
7
7
 
8
8
  end
9
9
 
@@ -37,6 +37,8 @@ module Restforce
37
37
  #
38
38
  # Returns nothing.
39
39
  def start
40
+ DB.configure { |config| config.logger = logger }
41
+
40
42
  trap_signals
41
43
 
42
44
  loop do
data/lib/restforce/db.rb CHANGED
@@ -64,7 +64,7 @@ module Restforce
64
64
  :configuration,
65
65
  :logger,
66
66
  :logger=,
67
- :after_fork,
67
+ :before,
68
68
  )
69
69
 
70
70
  end
@@ -8,29 +8,38 @@ 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
11
+ describe "#before" do
12
12
 
13
13
  it "does nothing if invoked without a block" do
14
14
  # NOTE: We're asserting that this invocation doesn't raise an error.
15
- configuration.after_fork
15
+ configuration.before
16
16
  end
17
17
 
18
- it "does not invoke the block on configuration" do
18
+ it "does not invoke the hook on configuration" do
19
19
  a = 1
20
20
 
21
- configuration.after_fork { a += 1 }
21
+ configuration.before { a += 1 }
22
22
 
23
23
  expect(a).to_equal 1
24
24
  end
25
25
 
26
- it "invokes the configured block when called without arguments" do
26
+ it "invokes the configured hook when called without a block" do
27
27
  a = 1
28
28
 
29
- configuration.after_fork { a += 1 }
30
- configuration.after_fork
29
+ configuration.before { a += 1 }
30
+ configuration.before
31
31
 
32
32
  expect(a).to_equal 2
33
33
  end
34
+
35
+ it "invokes the configured hook with passed arguments" do
36
+ a = 1
37
+
38
+ configuration.before { |b| a += b }
39
+ configuration.before(2)
40
+
41
+ expect(a).to_equal 3
42
+ end
34
43
  end
35
44
 
36
45
  describe "#logger" do
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: 2.1.6
4
+ version: 2.2.0
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-06-01 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord