metaforce 1.0.4 → 1.0.5
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.
- data/lib/metaforce.rb +1 -0
- data/lib/metaforce/cli.rb +4 -2
- data/lib/metaforce/config.rb +8 -0
- data/lib/metaforce/job.rb +31 -35
- data/lib/metaforce/version.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- metadata +2 -2
data/lib/metaforce.rb
CHANGED
@@ -23,6 +23,7 @@ module Metaforce
|
|
23
23
|
|
24
24
|
# Performs a login and retrurns the session
|
25
25
|
def login(options={})
|
26
|
+
options = HashWithIndifferentAccess.new(options)
|
26
27
|
username = options.fetch(:username, ENV['SALESFORCE_USERNAME'])
|
27
28
|
password = options.fetch(:password, ENV['SALESFORCE_PASSWORD'])
|
28
29
|
security_token = options.fetch(:security_token, ENV['SALESFORCE_SECURITY_TOKEN'])
|
data/lib/metaforce/cli.rb
CHANGED
@@ -2,8 +2,10 @@ require 'listen'
|
|
2
2
|
require 'thor'
|
3
3
|
require 'metaforce/reporters'
|
4
4
|
|
5
|
-
Metaforce.
|
6
|
-
|
5
|
+
Metaforce.configure do |config|
|
6
|
+
config.log = false
|
7
|
+
config.threading = false
|
8
|
+
end
|
7
9
|
|
8
10
|
module Metaforce
|
9
11
|
class CLI < Thor
|
data/lib/metaforce/config.rb
CHANGED
@@ -47,6 +47,14 @@ module Metaforce
|
|
47
47
|
# options. The block should set the options to a hash containing a valid
|
48
48
|
# session_id and service urls.
|
49
49
|
attr_accessor :authentication_handler
|
50
|
+
# Enables or disables threading when polling for job status. If disabled,
|
51
|
+
# calling .perform on a job will block until completion and all callbacks
|
52
|
+
# have run. (default: true).
|
53
|
+
attr_accessor :threading
|
54
|
+
|
55
|
+
def initialize
|
56
|
+
@threading = false
|
57
|
+
end
|
50
58
|
|
51
59
|
def api_version
|
52
60
|
@api_version ||= '26.0'
|
data/lib/metaforce/job.rb
CHANGED
@@ -142,23 +142,11 @@ module Metaforce
|
|
142
142
|
"#<#{self.class} @id=#{@id.inspect}>"
|
143
143
|
end
|
144
144
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
def start_heart_beat
|
151
|
-
delay = DELAY_START
|
152
|
-
loop do
|
153
|
-
@status = nil
|
154
|
-
wait (delay = delay * DELAY_MULTIPLIER)
|
155
|
-
trigger_poll_callbacks
|
156
|
-
trigger_callbacks && break if completed? || error?
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
145
|
+
def self.disable_threading!
|
146
|
+
ActiveSupport::Deprecation.warn <<-WARNING.strip_heredoc
|
147
|
+
Metaforce::Job.disable_threading! is deprecated. Use Metaforce.configuration.threading = false instead.
|
148
|
+
WARNING
|
149
|
+
Metaforce.configuration.threading = false
|
162
150
|
end
|
163
151
|
|
164
152
|
private
|
@@ -167,30 +155,34 @@ module Metaforce
|
|
167
155
|
# Internal: Starts a heart beat in a thread, which polls the job status
|
168
156
|
# until it has completed or timed out.
|
169
157
|
def start_heart_beat
|
170
|
-
|
171
|
-
|
158
|
+
if threading?
|
159
|
+
Thread.abort_on_exception = true
|
160
|
+
@heart_beat ||= Thread.new &run_loop
|
161
|
+
else
|
162
|
+
run_loop.call
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Internal: Starts the run loop, and blocks until the job has completed or
|
167
|
+
# failed.
|
168
|
+
def run_loop
|
169
|
+
proc {
|
172
170
|
delay = DELAY_START
|
173
171
|
loop do
|
174
172
|
@status = nil
|
175
|
-
|
176
|
-
|
177
|
-
|
173
|
+
sleep (delay = delay * DELAY_MULTIPLIER)
|
174
|
+
trigger :on_poll
|
175
|
+
if completed? || error?
|
176
|
+
trigger callback_type
|
177
|
+
Thread.stop if threading?
|
178
|
+
break
|
179
|
+
end
|
178
180
|
end
|
179
|
-
|
181
|
+
}
|
180
182
|
end
|
181
183
|
|
182
|
-
def
|
183
|
-
@_callbacks[
|
184
|
-
block.call(self)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def wait(duration)
|
189
|
-
sleep duration
|
190
|
-
end
|
191
|
-
|
192
|
-
def trigger_callbacks
|
193
|
-
@_callbacks[callback_type].each do |block|
|
184
|
+
def trigger(type)
|
185
|
+
@_callbacks[type].each do |block|
|
194
186
|
block.call(self)
|
195
187
|
end
|
196
188
|
end
|
@@ -203,5 +195,9 @@ module Metaforce
|
|
203
195
|
end
|
204
196
|
end
|
205
197
|
|
198
|
+
def threading?
|
199
|
+
Metaforce.configuration.threading
|
200
|
+
end
|
201
|
+
|
206
202
|
end
|
207
203
|
end
|
data/lib/metaforce/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -10,8 +10,8 @@ RSpec.configure do |config|
|
|
10
10
|
config.include Savon::Spec::Macros
|
11
11
|
|
12
12
|
config.before(:each) do
|
13
|
-
Metaforce
|
14
|
-
Metaforce::Job.any_instance.stub(:
|
13
|
+
Metaforce.configuration.threading = false
|
14
|
+
Metaforce::Job.any_instance.stub(:sleep)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metaforce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: savon
|