Class: Evesync::Sync

Inherits:
Object
  • Object
show all
Defined in:
lib/evesync/sync.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSync

Returns a new instance of Sync.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/evesync/sync.rb', line 12

def initialize
  @discovery = Discover.new
  @monitor = IPC::Client.new(
    port: :evemond
  )
  @database = IPC::Client.new(
    port: :evedatad
  )
  @handler = IPC::Client.new(
    port: :evehand
  )
end

Class Method Details

.diff_missed(params) ⇒ Object

Diffs missed of ‘v1’ that ‘v2’ contain



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/evesync/sync.rb', line 58

def self.diff_missed(params)
  v1 = params[:v1]
  v2 = params[:v2]

  # Fully missed objects
  fully_missed = v2.reject { |k| v1.include?(k) }

  # Included in both, but may be missed in `v1'
  maybe_missed = v2.select { |k| v1.include?(k) }

  not_relevant = maybe_missed.select do |k, v|
    v.max > v1[k].max
  end

  partially_missed = not_relevant.map do |k, v|
    [k, v.select { |tms| tms > v1[k].max }]
  end.to_h

  fully_missed.merge(partially_missed)
end

Instance Method Details

#apply_events(events) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/evesync/sync.rb', line 48

def apply_events(events)
  events.each do |_, message|
    message.values.each do |json|
      ipc_message = IPC::Data.from_json(json)
      @handler.handle(ipc_message)
    end
  end
end

#discoverObject

Sending a discovery message to broadcast. Local UDP socket listens and responses for handling answers.



44
45
46
# File 'lib/evesync/sync.rb', line 44

def discover
  @discovery.send_discovery_message
end

#synchronizeObject

Starting Synchronization between nodes that are found. Checking if all events are synchronized and synchronizing missing events.

TODO:

* Catch the time when an event is sent while
  synchronizing


34
35
36
37
38
# File 'lib/evesync/sync.rb', line 34

def synchronize
  Log.debug('Synchronizing starting...')
  apply_events fetch_events missed_events
  Log.debug('Synchronizing done!')
end