Class: Logux::Node

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/logux/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_timeObject

Returns the value of attribute last_time.



7
8
9
# File 'lib/logux/node.rb', line 7

def last_time
  @last_time
end

#node_idObject



23
24
25
# File 'lib/logux/node.rb', line 23

def node_id
  @node_id ||= "server:#{Nanoid.generate(size: 8)}"
end

#sequenceObject

Returns the value of attribute sequence.



7
8
9
# File 'lib/logux/node.rb', line 7

def sequence
  @sequence
end

Instance Method Details

#generate_action_idObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/logux/node.rb', line 10

def generate_action_id
  mutex.synchronize do
    if last_time && now_time <= last_time
      @sequence += 1
    else
      @sequence = 0
      @last_time = now_time
    end

    "#{last_time} #{node_id} #{sequence}"
  end
end