Class: RailsServerMonitor::TakeSnapshot

Inherits:
Object
  • Object
show all
Defined in:
app/services/rails_server_monitor/take_snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ TakeSnapshot

Returns a new instance of TakeSnapshot.



7
8
9
# File 'app/services/rails_server_monitor/take_snapshot.rb', line 7

def initialize(server)
  @server = server
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'app/services/rails_server_monitor/take_snapshot.rb', line 5

def server
  @server
end

Instance Method Details

#callObject



11
12
13
14
# File 'app/services/rails_server_monitor/take_snapshot.rb', line 11

def call
  return unless can_take_snapshot?
  create_snapshot!
end

#can_take_snapshot?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/rails_server_monitor/take_snapshot.rb', line 16

def can_take_snapshot?
  return @can_take_snapshot if defined? @can_take_snapshot
  latest_snapshot = server.server_snapshots.order(id: :desc).first
  if latest_snapshot.blank?
    return @can_take_snapshot = true
  end
  if (Time.zone.now - latest_snapshot.created_at) >= config.snapshot_server_interval
    return @can_take_snapshot = true
  end

  @can_take_snapshot = false
end