Class: DownloadQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/enigmamachine/download_queue.rb

Instance Method Summary collapse

Constructor Details

#initializeDownloadQueue

Adds a periodic timer to the Eventmachine reactor loop and immediately starts looking for videos to download.



6
7
8
9
10
11
12
# File 'lib/enigmamachine/download_queue.rb', line 6

def initialize
  if EnigmaMachine.enable_http_downloads
    EM.add_periodic_timer(5) do
      download_next_video
    end
  end
end

Instance Method Details

#download_next_videoObject

Gets the next waiting_for_download Video from the database and starts downloading it.



18
19
20
21
22
23
24
25
26
27
# File 'lib/enigmamachine/download_queue.rb', line 18

def download_next_video
  if Video.waiting_for_download.count > 0 && Video.downloading.count == 0
    video = Video.waiting_for_download.first
    begin
      video.download!
    rescue Exception => ex
      # don't do anything just yet, until we set up logging properly.
    end
  end
end