Sha256: 797e477de8f15691b63100e97a007b8a770c27bc38fc1c724e6b665d2239a8cb

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Github
  module Archive
    class StatCollector
      @queue = :github_archive

      class << self
        attr_reader :queue

        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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
github-archive-0.0.1 lib/github/archive/stat_collector.rb