Module: ActsAsTbackend::Extension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/acts_as_tbackend/extension.rb
Overview
ActiveRecord integration for the refreshed core. acts_as_tbackend mirrors model
lifecycle to TBackend on after_commit — synchronously, with a soft/non-fatal
result (a down daemon never raises into the request path). For heavy write paths,
call record.tbackend_fact(...) from your own background job instead.
class Order < ApplicationRecord
acts_as_tbackend store: "orders", except: %i[created_at updated_at]
end
Class Method Summary collapse
Instance Method Summary collapse
- #mirror_tbackend(event_type:, tombstone: false) ⇒ Object
-
#tbackend_fact(event_type:, tombstone: false) ⇒ Object
Public: build the fact for this record (no write) — for apps mirroring from their own job.
Class Method Details
.log(message) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/acts_as_tbackend/extension.rb', line 79 def self.log() if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger Rails.logger.error("[ActsAsTbackend] #{}") else warn "[ActsAsTbackend] #{}" end end |
Instance Method Details
#mirror_tbackend(event_type:, tombstone: false) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/acts_as_tbackend/extension.rb', line 68 def mirror_tbackend(event_type:, tombstone: false) opts = self.class. ActsAsTbackend::Mirror.mirror!( record: self, store: opts[:store], event_type: event_type, only: opts[:only], except: opts[:except], tombstone: tombstone, valid_time: valid_time ) rescue StandardError => e ActsAsTbackend::Extension.log("mirror error: #{e.}") { ok: false, status: "error", committed: nil, retryable: nil, response: nil, error: e. } end |
#tbackend_fact(event_type:, tombstone: false) ⇒ Object
Public: build the fact for this record (no write) — for apps mirroring from their own job.
60 61 62 63 64 65 66 |
# File 'lib/acts_as_tbackend/extension.rb', line 60 def tbackend_fact(event_type:, tombstone: false) opts = self.class. ActsAsTbackend::Mirror.build_fact( record: self, store: opts[:store], event_type: event_type, only: opts[:only], except: opts[:except], tombstone: tombstone, valid_time: valid_time ) end |