Module: SalesforceBulkApi::Concerns::Throttling
- Included in:
- SalesforceBulkApi::Connection
- Defined in:
- lib/salesforce_bulk_api/concerns/throttling.rb
Instance Method Summary collapse
- #add_throttle(&throttling_callback) ⇒ Object
- #set_status_throttle(limit_seconds) ⇒ Object
- #set_throttle_limit_in_seconds(limit_seconds, throttle_by_keys, only_if) ⇒ Object
- #throttles ⇒ Object
Instance Method Details
#add_throttle(&throttling_callback) ⇒ Object
8 9 10 11 |
# File 'lib/salesforce_bulk_api/concerns/throttling.rb', line 8 def add_throttle(&throttling_callback) @throttles ||= [] @throttles << throttling_callback end |
#set_status_throttle(limit_seconds) ⇒ Object
13 14 15 |
# File 'lib/salesforce_bulk_api/concerns/throttling.rb', line 13 def set_status_throttle(limit_seconds) set_throttle_limit_in_seconds(limit_seconds, [:http_method, :path], ->(details) { details[:http_method] == :get }) end |
#set_throttle_limit_in_seconds(limit_seconds, throttle_by_keys, only_if) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/salesforce_bulk_api/concerns/throttling.rb', line 17 def set_throttle_limit_in_seconds(limit_seconds, throttle_by_keys, only_if) add_throttle do |details| limit_log = get_limit_log(Time.now - limit_seconds) key = extract_constraint_key_from(details, throttle_by_keys) last_request = limit_log[key] if !last_request.nil? && only_if.call(details) seconds_since_last_request = Time.now.to_f - last_request.to_f need_to_wait_seconds = limit_seconds - seconds_since_last_request sleep(need_to_wait_seconds) if need_to_wait_seconds > 0 end limit_log[key] = Time.now end end |
#throttles ⇒ Object
4 5 6 |
# File 'lib/salesforce_bulk_api/concerns/throttling.rb', line 4 def throttles @throttles.dup end |