Module: Legion::Transport::TenantProvisioner

Extended by:
Logging::Helper
Defined in:
lib/legion/transport/tenant_provisioner.rb

Constant Summary collapse

EXCHANGE_TYPES =
%w[tasks results events].freeze

Class Method Summary collapse

Class Method Details

.deprovision(tenant_id, channel: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legion/transport/tenant_provisioner.rb', line 29

def self.deprovision(tenant_id, channel: nil)
  ch = channel || Legion::Transport.connection.create_channel
  (EXCHANGE_TYPES + ['dlx']).each do |type|
    name = TenantTopology.exchange_name(type, tenant_id: tenant_id)
    begin
      ch.exchange_delete(name)
    rescue StandardError => e
      handle_exception(e, level: :warn, handled: true, operation: 'transport.tenant_provisioner.deprovision_exchange',
                       tenant_id: tenant_id, exchange_name: name)
      nil
    end
  end
  ch.close unless channel
  log.info "Deprovisioned tenant topology for tenant_id=#{tenant_id}"
rescue StandardError => e
  handle_exception(e, level: :warn, handled: false, operation: 'transport.tenant_provisioner.deprovision',
                   tenant_id: tenant_id)
  raise
end

.provision(tenant_id, channel: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/transport/tenant_provisioner.rb', line 13

def self.provision(tenant_id, channel: nil)
  ch = channel || Legion::Transport.connection.create_channel
  EXCHANGE_TYPES.each do |type|
    name = TenantTopology.exchange_name(type, tenant_id: tenant_id)
    ch.topic(name, durable: true)
  end
  dlx = TenantTopology.exchange_name('dlx', tenant_id: tenant_id)
  ch.fanout(dlx, durable: true)
  ch.close unless channel
  log.info "Provisioned tenant topology for tenant_id=#{tenant_id}"
rescue StandardError => e
  handle_exception(e, level: :warn, handled: false, operation: 'transport.tenant_provisioner.provision',
                   tenant_id: tenant_id)
  raise
end