Module: Legion::Transport::TenantProvisioner

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/legion/transport/tenant_provisioner.rb', line 25

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
      Legion::Logging.debug("TenantProvisioner#deprovision exchange delete failed for #{name}: #{e.message}") if defined?(Legion::Logging)
      nil
    end
  end
  ch.close unless channel
  Legion::Logging.info "Deprovisioned tenant topology for tenant_id=#{tenant_id}" if defined?(Legion::Logging)
rescue StandardError => e
  Legion::Logging.warn "Failed to deprovision tenant topology for tenant_id=#{tenant_id}: #{e.message}" if defined?(Legion::Logging)
  raise
end

.provision(tenant_id, channel: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/transport/tenant_provisioner.rb', line 10

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
  Legion::Logging.info "Provisioned tenant topology for tenant_id=#{tenant_id}" if defined?(Legion::Logging)
rescue StandardError => e
  Legion::Logging.warn "Failed to provision tenant topology for tenant_id=#{tenant_id}: #{e.message}" if defined?(Legion::Logging)
  raise
end