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 = nil, 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 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 = nil, tth = nil, size = -1,, offset = 0) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fargo/supports/downloads.rb', line 30 def download nick, file=nil, tth=nil, size=-1, offset=0 raise ConnectionException.new 'Not connected yet!' unless hub if nick.is_a?(Supports::FileList::Listing) listing = nick nick = listing.nick file = listing.name tth = listing.tth size = listing.size elsif nick.is_a?(Download) dl = nick nick = dl.nick file = dl.file tth = dl.tth size = dl.size || -1 offset = dl.offset || 0 end raise 'File must not be nil!' if file.nil? unless nicks.include? nick raise ConnectionException.new "User #{nick} does not exist!" end tth = tth.gsub /^TTH:/, '' if tth 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
84 85 86 87 88 |
# File 'lib/fargo/supports/downloads.rb', line 84 def lock_next_download! user, connection @downloading_lock.synchronize { return get_next_download_with_lock! user, connection } end |
#remove_download(nick, file) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/fargo/supports/downloads.rb', line 77 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
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fargo/supports/downloads.rb', line 65 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
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fargo/supports/downloads.rb', line 91 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 |