Class: Github::Archive::StatCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/github/archive/stat_collector.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.queueObject (readonly)

Returns the value of attribute queue.



7
8
9
# File 'lib/github/archive/stat_collector.rb', line 7

def queue
  @queue
end

Class Method Details

.perform(stat_url) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/github/archive/stat_collector.rb', line 9

def perform(stat_url)
  archived = ArchivedUrl.where(url: stat_url).first

  if archived.nil?
    puts "cannot archive untracked url #{stat_url}"
  elsif archived.finished_processing
    puts "already processed #{stat_url}"
  else
    begin
      ArchivedUrl.transaction do
        puts "processing #{stat_url}"
        gz = open(stat_url)
        js = Zlib::GzipReader.new(gz).read
        Yajl::Parser.parse(js) do |event|
          Github::Archive::Event.create_with_json(event)
        end

        archived.finished_processing = true
        archived.save
      end
    rescue
      puts "There was some kind of error while parsing #{stat_url}"
      archived.finished_processing = true
      archived.save
    end
  end
end