Module: Connect::Record
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/connect/record.rb
Instance Method Summary collapse
-
#await_sync(timeout: 25, poll: 5, allocate_sfid_locally: !Rails.env.production?)) ⇒ Object
Waits until salesforce allocates an SFID and syncs it back to heroku connect.
- #readonly? ⇒ Boolean
- #sync_failed? ⇒ Boolean
- #synced? ⇒ Boolean
Instance Method Details
#await_sync(timeout: 25, poll: 5, allocate_sfid_locally: !Rails.env.production?)) ⇒ Object
Waits until salesforce allocates an SFID and syncs it back to heroku connect. Persistent failures can occur E.G. if there are duplication rules on the salesforce side.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/connect/record.rb', line 57 def await_sync(timeout: 25, poll: 5, allocate_sfid_locally: !Rails.env.production?) return true if synced? if allocate_sfid_locally update sfid: SecureRandom.base58(18) else begin Timeout::timeout(timeout) do loop do sleep poll if reload.synced? break end return false if sync_failed? # Bail immediately if sync fails end end rescue Timeout::Error return false end end true end |
#readonly? ⇒ Boolean
41 42 43 44 |
# File 'lib/connect/record.rb', line 41 def readonly? return false unless self.class.syncs_to_salesforce? super end |
#sync_failed? ⇒ Boolean
50 51 52 |
# File 'lib/connect/record.rb', line 50 def sync_failed? _hc_err.present? end |
#synced? ⇒ Boolean
46 47 48 |
# File 'lib/connect/record.rb', line 46 def synced? _hc_err.blank? && sfid.present? end |