Module: Vert::Rls::ConsumerContext

Extended by:
ActiveSupport::Concern
Defined in:
lib/vert/rls/consumer_context.rb

Instance Method Summary collapse

Instance Method Details

#with_rls_contextObject

Convenience wrapper for consumers that want to explicitly mark the RLS-protected block. Context is already set by work_with_params, so this simply yields the block.



28
29
30
# File 'lib/vert/rls/consumer_context.rb', line 28

def with_rls_context
  yield
end

#work_with_params(message, delivery_info, metadata) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vert/rls/consumer_context.rb', line 8

def work_with_params(message, delivery_info, )
  h = [:headers] || {}
  Vert::Current.set_context(
    tenant_id: h["tenant_id"] || h[:tenant_id],
    user_id: h["user_id"] || h[:user_id],
    company_id: h["company_id"] || h[:company_id],
    request_id: h["request_id"] || h[:request_id] || SecureRandom.uuid
  )
  if Vert.config.enable_rls && Vert::Current.tenant_id.present?
    ConnectionHandler.set_context(tenant_id: Vert::Current.tenant_id, company_id: Vert::Current.company_id, user_id: Vert::Current.user_id)
  end
  work(message)
ensure
  Vert::Current.reset_all
  ConnectionHandler.reset_context if Vert.config.enable_rls
end