Class: Evesync::Sync
- Inherits:
-
Object
- Object
- Evesync::Sync
- Defined in:
- lib/evesync/sync.rb
Class Method Summary collapse
-
.diff_missed(params) ⇒ Object
Diffs missed of ‘v1’ that ‘v2’ contain.
Instance Method Summary collapse
- #apply_events(events) ⇒ Object
-
#discover ⇒ Object
Sending a discovery message to broadcast.
-
#initialize ⇒ Sync
constructor
A new instance of Sync.
-
#synchronize ⇒ Object
Starting Synchronization between nodes that are found.
Constructor Details
#initialize ⇒ Sync
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 |_, | .values.each do |json| = IPC::Data.from_json(json) @handler.handle() end end end |
#discover ⇒ Object
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. end |
#synchronize ⇒ Object
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 |