Class: MyLocalPutio::DiskManager

Inherits:
Object
  • Object
show all
Defined in:
lib/my-local-putio/disk_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ DiskManager

Returns a new instance of DiskManager.



5
6
7
8
# File 'lib/my-local-putio/disk_manager.rb', line 5

def initialize(configuration)
  @configuration = configuration
  @logger = configuration.logger
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/my-local-putio/disk_manager.rb', line 3

def configuration
  @configuration
end

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/my-local-putio/disk_manager.rb', line 3

def logger
  @logger
end

Instance Method Details

#check_for_available_space_on_destinations!(needed_space) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/my-local-putio/disk_manager.rb', line 10

def check_for_available_space_on_destinations!(needed_space)
  return unless configuration.disk_threshold

  [configuration.local_destination, configuration.temp_destination].each do |path|
    free_space = get_folder_free_space(path)
    next unless (free_space - configuration.disk_threshold) <= needed_space
    logger.log "Low disk threshold on path: #{path}! Stopping the script!"
    exit
  end
end

#get_folder_free_space(destination) ⇒ Object



21
22
23
24
# File 'lib/my-local-putio/disk_manager.rb', line 21

def get_folder_free_space(destination)
  space = `df -Pk #{destination}/ | awk 'NR==2 {print $4}'`.to_i
  (space/1024).to_i.round(2)
end