Class: Ruote::WfidGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/id/wfid_generator.rb

Overview

An example of wfid generator.

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ WfidGenerator

Returns a new instance of WfidGenerator



35
36
37
38
39
40
41
42
# File 'lib/ruote/id/wfid_generator.rb', line 35

def initialize(context)

  @context = context

  @here = "#{Ruote.local_ip}!#{Process.pid}"
  @counter = 0
  #@mutex = Mutex.new
end

Instance Method Details

#generateObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruote/id/wfid_generator.rb', line 44

def generate

  t = Time.now.utc
  time = t.strftime('%Y%m%d-%H%M%S')
  ms = t.to_f % 1.0

  #c = @mutex.synchronize { @counter = (@counter + 1) % 10_000 }
  c = @counter = (@counter + 1) % 10_000

  x = "#{ms}!#{Thread.current.object_id}!#{@here}!#{c}"
  x = Digest::MD5.hexdigest(x)

  "#{time}-#{x}"
end