Skip to content

Commit

Permalink
Feed parsing, call update when new entries
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrelsouza committed Sep 11, 2019
1 parent f9147e6 commit 94df9ef
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -14,4 +14,4 @@ COPY Gemfile Gemfile.lock /usr/src/app/
RUN bundle install --without test --jobs 2

COPY . /usr/src/app
CMD puma
CMD ["puma"]
36 changes: 21 additions & 15 deletions conda.rb
Expand Up @@ -21,10 +21,13 @@ def initialize
@redis = MockRedis.new
else
@redis = Redis.new(url: ENV["REDIS_SERVER"], driver: :hiredis)
update_packages
end
end

###########
# Getters # -> Used for Api Calls
###########

def package_names
@redis.smembers("package_names").sort
end
Expand All @@ -36,23 +39,13 @@ def package(channel, name)
MessagePack.unpack(pack.force_encoding("ASCII-8BIT"))
end

def download_and_parse_packages
channels_with_packages = {}
CHANNELS.each do |channel, domain|
channel_packages = download_json(channel, domain)["packages"]
channels_with_packages[channel] ||= {}
channel_packages.each do |package_name, package|
channels_with_packages[channel][package_name] = package
end
end

channels_with_packages
end
###########
# Setters # -> Things to set up the data
###########

def update_packages
download_and_parse_packages.each do |channel, packages|
@redis.sadd("package_names", packages.keys.map { |name| "#{channel}/#{name}" })

packages.each do |name, package_info|
version = package_info["version"]
key = "#{channel}/#{name}"
Expand All @@ -61,9 +54,22 @@ def update_packages
end
end

def download_and_parse_packages
channels_with_packages = {}
CHANNELS.each do |channel, domain|
channel_packages = download_channeldata(channel, domain)["packages"]
channels_with_packages[channel] ||= {}
channel_packages.each do |package_name, package|
channels_with_packages[channel][package_name] = package
end
end

channels_with_packages
end

private

def download_json(channel, domain)
def download_channeldata(channel, domain)
url = "https://#{domain}/#{channel}/channeldata.json"
HTTParty.get(url).parsed_response
end
Expand Down
26 changes: 14 additions & 12 deletions feed.rb
@@ -1,16 +1,18 @@
require 'bundler'
Bundler.require

require './conda_repo'
require './conda'

# redis_uri = ENV['REDIS_SERVER'] || 'localhost:6379'
# client = Feedtosis::Client.new('https://repo.anaconda.com/pkgs/rss.xml',
# backend: Moneta.new(:Redis,
# host: URI.parse(redis_uri).host,
# port: URI.parse(redis_uri).port))
# TODO: do this in next PR
# while(true) do
# new_entries = client.fetch.new_entries
# CocoapodsRepo.new(redis_uri).update_pods if new_entries
# sleep 30
# end
redis_uri = ENV['REDIS_SERVER'] || 'localhost:6379'
client = Feedtosis::Client.new('http://repo.anaconda.com/pkgs/rss.xml',
backend: Moneta.new(:Redis,
host: URI.parse(redis_uri).host,
port: URI.parse(redis_uri).port))
loop do
new_entries = client.fetch.new_entries
if new_entries.length
puts "#{new_entries.length} new"
Conda.instance.update_packages
end
sleep 30
end
2 changes: 1 addition & 1 deletion spec/conda_spec.rb
Expand Up @@ -4,7 +4,7 @@
describe "Conda" do
subject { described_class.instance }
before do
allow(subject).to receive(:download_json).and_return(json_load_fixture("pkgs/main.json"))
allow(subject).to receive(:download_channeldata).and_return(json_load_fixture("pkgs/main.json"))
end

it "loads packages" do
Expand Down

0 comments on commit 94df9ef

Please sign in to comment.