Class: WebArchive::ArchiveQueue

Inherits:
Queue
  • Object
show all
Defined in:
lib/webarchive.rb

Overview

Queue for sending URLs to a certain archiving web site The block given to constructor will be executed for each ‘<<’

Instance Method Summary collapse

Constructor Details

#initialize(name, wait) ⇒ ArchiveQueue

Returns a new instance of ArchiveQueue.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/webarchive.rb', line 34

def initialize(name, wait)
  super()
  @name = name
  @all_sent = false
  @in_process = 0             # always <= 1
  @consumer = Thread.new do
    loop do
      uri = self.pop
      @in_process += 1
      begin
        yield uri
      rescue StandardError => e
        WebArchive.warn_archive_fail(
          uri, name, ([e.inspect] + e.backtrace).join("\n")
        )
      ensure
        @in_process -= 1
        break if @all_sent && self.empty?

        sleep wait
      end
    end
  end
end

Instance Method Details

#done_sendingObject

mark as ‘sending done’ and wait for items to be processed



60
61
62
63
# File 'lib/webarchive.rb', line 60

def done_sending
  @all_sent = true
  @consumer.join if self.remaining > 0
end

#remainingObject

number of queued items (including those being processed)



66
67
68
# File 'lib/webarchive.rb', line 66

def remaining
  self.size + @in_process
end