Class: GlobalUid::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/global_uid/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Set defaults



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/global_uid/configuration.rb', line 18

def initialize
  # Timeout (in seconds) for connecting to a global UID server
  @connection_timeout = 3

  # Duration (in seconds) to wait before attempting another connection to UID server
  @connection_retry = 600 # 10 minutes

  # An object that will be notified in case of a UID server failure.
  # The object is expected to respond to `#call`, which will be passed one argument of type `Exception`.
  @notifier = GlobalUid::ErrorTracker.new

  # Timeout (in seconds) for retrieving a global UID from a server before moving to the next server
  @query_timeout = 10

  # Used for validation, compared with the value on the alloc servers to prevent allocation of duplicate IDs
  #   NB: The value configured here does not dictate the value on your alloc server and must remain in
  #       sync with the value of auto_increment_increment in the database.
  @increment_by = 5

  # Disable GlobalUid entirely
  @disabled = false

  # The same allocation server is used each time `with_servers` is called
  @connection_shuffling = false

  # Suppress configuration validation, allowing updates to auto_increment_increment while alloc servers in use.
  # The InvalidIncrementException will be swallowed and logged when suppressed
  @suppress_increment_exceptions = false

  # The name of the alloc DB servers, defined in your database.yml
  # e.g. ["id_server_1", "id_server_2"]
  @id_servers = []

  # The storage engine used during GloblaUid table creation
  # Supported and tested: InnoDB, MyISAM
  @storage_engine = "MyISAM"
end

Instance Attribute Details

#connection_retryObject

Returns the value of attribute connection_retry.



5
6
7
# File 'lib/global_uid/configuration.rb', line 5

def connection_retry
  @connection_retry
end

#connection_shufflingObject Also known as: connection_shuffling?

Returns the value of attribute connection_shuffling.



10
11
12
# File 'lib/global_uid/configuration.rb', line 10

def connection_shuffling
  @connection_shuffling
end

#connection_timeoutObject

Returns the value of attribute connection_timeout.



4
5
6
# File 'lib/global_uid/configuration.rb', line 4

def connection_timeout
  @connection_timeout
end

#disabledObject

Returns the value of attribute disabled.



9
10
11
# File 'lib/global_uid/configuration.rb', line 9

def disabled
  @disabled
end

#increment_byObject

Returns the value of attribute increment_by.



8
9
10
# File 'lib/global_uid/configuration.rb', line 8

def increment_by
  @increment_by
end

#notifierObject

Returns the value of attribute notifier.



6
7
8
# File 'lib/global_uid/configuration.rb', line 6

def notifier
  @notifier
end

#query_timeoutObject

Returns the value of attribute query_timeout.



7
8
9
# File 'lib/global_uid/configuration.rb', line 7

def query_timeout
  @query_timeout
end

#storage_engineObject

Returns the value of attribute storage_engine.



12
13
14
# File 'lib/global_uid/configuration.rb', line 12

def storage_engine
  @storage_engine
end

#suppress_increment_exceptionsObject Also known as: suppress_increment_exceptions?

Returns the value of attribute suppress_increment_exceptions.



11
12
13
# File 'lib/global_uid/configuration.rb', line 11

def suppress_increment_exceptions
  @suppress_increment_exceptions
end

Instance Method Details

#id_serversObject



61
62
63
64
# File 'lib/global_uid/configuration.rb', line 61

def id_servers
  raise "You haven't configured any id servers" if @id_servers.empty?
  @id_servers
end

#id_servers=(value) ⇒ Object



56
57
58
59
# File 'lib/global_uid/configuration.rb', line 56

def id_servers=(value)
  raise "More servers configured than increment_by: #{value.size} > #{increment_by} -- this will create duplicate IDs." if value.size > increment_by
  @id_servers = value
end