Class: InfluxDB2::WriteOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/influxdb2/client/write_api.rb

Overview

Creates write api configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(write_type: WriteType::SYNCHRONOUS, batch_size: 1_000, flush_interval: 1_000, retry_interval: 5_000, jitter_interval: 0, max_retries: 5, max_retry_delay: 125_000, max_retry_time: 180_000, exponential_base: 2, batch_abort_on_exception: false) ⇒ WriteOptions

Returns a new instance of WriteOptions.

Parameters:

  • write_type: (WriteType) (defaults to: WriteType::SYNCHRONOUS)

    methods of write (batching, synchronous)

  • batch_size: (Integer) (defaults to: 1_000)

    the number of data point to collect in batch

  • flush_interval: (Integer) (defaults to: 1_000)

    flush data at least in this interval

  • retry_interval: (Integer) (defaults to: 5_000)

    number of milliseconds to retry unsuccessful write. The retry interval is used when the InfluxDB server does not specify “Retry-After” header.

  • jitter_interval: (Integer) (defaults to: 0)

    the number of milliseconds to increase the batch flush interval

  • max_retries: (Integer) (defaults to: 5)

    max number of retries when write fails

  • max_retry_delay: (Integer) (defaults to: 125_000)

    maximum delay when retrying write in milliseconds

  • max_retry_time: (Integer) (defaults to: 180_000)

    maximum total retry timeout in milliseconds

  • exponential_base: (Integer) (defaults to: 2)

    the next delay is computed using random exponential backoff as a random value within the interval retry_interval*exponential_base^(attempts-1) and retry_interval*exponential_base^(attempts). Example for retry_interval=5000, exponential_base=2, max_retry_delay=125000, total=5 Retry delays are random distributed values within the ranges of

    5000-10000, 10000-20000, 20000-40000, 40000-80000, 80000-125000
  • batch_abort_on_exception: (Boolean) (defaults to: false)

    batching worker will be aborted after failed retry strategy



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/influxdb2/client/write_api.rb', line 46

def initialize(write_type: WriteType::SYNCHRONOUS, batch_size: 1_000, flush_interval: 1_000, retry_interval: 5_000,
               jitter_interval: 0, max_retries: 5, max_retry_delay: 125_000, max_retry_time: 180_000,
               exponential_base: 2, batch_abort_on_exception: false)
  _check_not_negative('batch_size', batch_size)
  _check_not_negative('flush_interval', flush_interval)
  _check_not_negative('retry_interval', retry_interval)
  _check_positive('jitter_interval', jitter_interval)
  _check_positive('max_retries', max_retries)
  _check_positive('max_retry_delay', max_retry_delay)
  _check_positive('max_retry_time', max_retry_time)
  _check_positive('exponential_base', exponential_base)
  @write_type = write_type
  @batch_size = batch_size
  @flush_interval = flush_interval
  @retry_interval = retry_interval
  @jitter_interval = jitter_interval
  @max_retries = max_retries
  @max_retry_delay = max_retry_delay
  @max_retry_time = max_retry_time
  @exponential_base = exponential_base
  @batch_abort_on_exception = batch_abort_on_exception
end

Instance Attribute Details

#batch_abort_on_exceptionObject (readonly)

Returns the value of attribute batch_abort_on_exception.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def batch_abort_on_exception
  @batch_abort_on_exception
end

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def batch_size
  @batch_size
end

#exponential_baseObject (readonly)

Returns the value of attribute exponential_base.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def exponential_base
  @exponential_base
end

#flush_intervalObject (readonly)

Returns the value of attribute flush_interval.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def flush_interval
  @flush_interval
end

#jitter_intervalObject (readonly)

Returns the value of attribute jitter_interval.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def jitter_interval
  @jitter_interval
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def max_retries
  @max_retries
end

#max_retry_delayObject (readonly)

Returns the value of attribute max_retry_delay.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def max_retry_delay
  @max_retry_delay
end

#max_retry_timeObject (readonly)

Returns the value of attribute max_retry_time.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def max_retry_time
  @max_retry_time
end

#retry_intervalObject (readonly)

Returns the value of attribute retry_interval.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def retry_interval
  @retry_interval
end

#write_typeObject (readonly)

Returns the value of attribute write_type.



69
70
71
# File 'lib/influxdb2/client/write_api.rb', line 69

def write_type
  @write_type
end

Instance Method Details

#_check_not_negative(key, value) ⇒ Object

Raises:

  • (ArgumentError)


72
73
74
# File 'lib/influxdb2/client/write_api.rb', line 72

def _check_not_negative(key, value)
  raise ArgumentError, "The '#{key}' should be positive or zero, but is: #{value}" if value <= 0
end

#_check_positive(key, value) ⇒ Object

Raises:

  • (ArgumentError)


76
77
78
# File 'lib/influxdb2/client/write_api.rb', line 76

def _check_positive(key, value)
  raise ArgumentError, "The '#{key}' should be positive number, but is: #{value}" if value < 0
end