Module: Fargo::Supports::Downloads
Defined Under Namespace
Classes: Download
Instance Attribute Summary collapse
-
#current_downloads ⇒ Object
readonly
Returns the value of attribute current_downloads.
-
#download_slots ⇒ Object
readonly
Returns the value of attribute download_slots.
-
#failed_downloads ⇒ Object
readonly
Returns the value of attribute failed_downloads.
-
#finished_downloads ⇒ Object
readonly
Returns the value of attribute finished_downloads.
-
#open_download_slots ⇒ Object
readonly
Returns the value of attribute open_download_slots.
-
#queued_downloads ⇒ Object
readonly
Returns the value of attribute queued_downloads.
-
#timed_out ⇒ Object
readonly
Returns the value of attribute timed_out.
-
#trying ⇒ Object
readonly
Returns the value of attribute trying.
Instance Method Summary collapse
- #clear_failed_downloads ⇒ Object
- #clear_finished_downloads ⇒ Object
- #download(nick, file, tth = nil, size = -1,, offset = 0) ⇒ Object
- #lock_next_download!(user, connection) ⇒ Object
- #remove_download(nick, file) ⇒ Object
- #retry_download(nick, file) ⇒ Object
-
#try_again(nick) ⇒ Object
If a connection timed out, retry all queued downloads for that user.
Instance Attribute Details
#current_downloads ⇒ Object (readonly)
Returns the value of attribute current_downloads.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def current_downloads @current_downloads end |
#download_slots ⇒ Object (readonly)
Returns the value of attribute download_slots.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def download_slots @download_slots end |
#failed_downloads ⇒ Object (readonly)
Returns the value of attribute failed_downloads.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def failed_downloads @failed_downloads end |
#finished_downloads ⇒ Object (readonly)
Returns the value of attribute finished_downloads.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def finished_downloads @finished_downloads end |
#open_download_slots ⇒ Object (readonly)
Returns the value of attribute open_download_slots.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def open_download_slots @open_download_slots end |
#queued_downloads ⇒ Object (readonly)
Returns the value of attribute queued_downloads.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def queued_downloads @queued_downloads end |
#timed_out ⇒ Object (readonly)
Returns the value of attribute timed_out.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def timed_out @timed_out end |
#trying ⇒ Object (readonly)
Returns the value of attribute trying.
14 15 16 |
# File 'lib/fargo/supports/downloads.rb', line 14 def @trying end |
Instance Method Details
#clear_failed_downloads ⇒ Object
22 23 24 |
# File 'lib/fargo/supports/downloads.rb', line 22 def clear_failed_downloads failed_downloads.clear end |
#clear_finished_downloads ⇒ Object
26 27 28 |
# File 'lib/fargo/supports/downloads.rb', line 26 def clear_finished_downloads finished_downloads.clear end |
#download(nick, file, tth = nil, size = -1,, offset = 0) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fargo/supports/downloads.rb', line 30 def download nick, file, tth=nil, size=-1, offset=0 raise ConnectionException.new 'Not connected yet!' unless hub raise 'File cannot be nil!' if file.nil? unless nicks.include? nick raise ConnectionException.new "User #{nick} does not exist!" end download = Download.new nick, file, tth, size, offset download.percent = 0 download.status = 'idle' # Append it to the queue of things to download. This will be processed # elsewhere @to_download << download true end |
#lock_next_download!(user, connection) ⇒ Object
67 68 69 70 71 |
# File 'lib/fargo/supports/downloads.rb', line 67 def lock_next_download! user, connection @downloading_lock.synchronize { return get_next_download_with_lock! user, connection } end |
#remove_download(nick, file) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/fargo/supports/downloads.rb', line 60 def remove_download nick, file # We need to synchronize this access, so append these arguments to a # queue to be processed later @to_remove << [nick, file] true end |
#retry_download(nick, file) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fargo/supports/downloads.rb', line 48 def retry_download nick, file dl = (@failed_downloads[nick] ||= []).detect{ |h| h.file == file } if dl.nil? Fargo.logger.warn "#{file} isn't a failed download for: #{nick}!" return end @failed_downloads[nick].delete dl download dl.nick, dl.file, dl.tth, dl.size end |
#try_again(nick) ⇒ Object
If a connection timed out, retry all queued downloads for that user
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fargo/supports/downloads.rb', line 74 def try_again nick return false unless @timed_out.include? nick @timed_out.delete nick downloads = @failed_downloads[nick].dup @failed_downloads[nick].clear downloads.each{ |d| download nick, d.file, d.tth, d.size } true end |