Class: Async::Background::Queue::StoreOptions

Inherits:
Data
  • Object
show all
Defined in:
lib/async/background/queue/store.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mmap:, synchronous:, wal_autocheckpoint:) ⇒ StoreOptions

Returns a new instance of StoreOptions.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/async/background/queue/store.rb', line 17

def initialize(mmap:, synchronous:, wal_autocheckpoint:)
  unless mmap == true || mmap == false
    raise ArgumentError, "mmap must be true or false, got #{mmap.inspect}"
  end

  unless SYNCHRONOUS_LEVELS.key?(synchronous)
    raise ArgumentError,
      "synchronous must be one of #{SYNCHRONOUS_LEVELS.keys.inspect}, got #{synchronous.inspect}"
  end

  unless wal_autocheckpoint.is_a?(Integer) && WAL_AUTOCHECKPOINT_RANGE.cover?(wal_autocheckpoint)
    raise ArgumentError,
      "wal_autocheckpoint must be an Integer in #{WAL_AUTOCHECKPOINT_RANGE}, " \
      "got #{wal_autocheckpoint.inspect}"
  end

  super
end

Instance Attribute Details

#mmapObject (readonly)

Returns the value of attribute mmap

Returns:

  • (Object)

    the current value of mmap



14
15
16
# File 'lib/async/background/queue/store.rb', line 14

def mmap
  @mmap
end

#synchronousObject (readonly)

Returns the value of attribute synchronous

Returns:

  • (Object)

    the current value of synchronous



14
15
16
# File 'lib/async/background/queue/store.rb', line 14

def synchronous
  @synchronous
end

#wal_autocheckpointObject (readonly)

Returns the value of attribute wal_autocheckpoint

Returns:

  • (Object)

    the current value of wal_autocheckpoint



14
15
16
# File 'lib/async/background/queue/store.rb', line 14

def wal_autocheckpoint
  @wal_autocheckpoint
end

Class Method Details

.build(value = {}) ⇒ Object



15
# File 'lib/async/background/queue/store.rb', line 15

def self.build(value = {}) = value.is_a?(self) ? value : new(**DEFAULTS, **value)

Instance Method Details

#mmap_sizeObject



37
# File 'lib/async/background/queue/store.rb', line 37

def mmap_size = mmap ? MMAP_SIZE : 0

#pragma_sqlObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/async/background/queue/store.rb', line 39

def pragma_sql
  <<~SQL
    PRAGMA journal_mode       = WAL;
    PRAGMA synchronous        = #{synchronous_pragma};
    PRAGMA mmap_size          = #{mmap_size};
    PRAGMA cache_size         = -16000;
    PRAGMA temp_store         = MEMORY;
    PRAGMA journal_size_limit = 67108864;
    PRAGMA wal_autocheckpoint = #{wal_autocheckpoint};
  SQL
end

#synchronous_pragmaObject



36
# File 'lib/async/background/queue/store.rb', line 36

def synchronous_pragma = SYNCHRONOUS_LEVELS.fetch(synchronous)