Skip to content

Commit

Permalink
fix: correct timeout bug
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Feb 2, 2022
1 parent 3c7cbf3 commit c23c5c4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 0.4.4

Fix timeout being incorrectly called.

# Version 0.4.3

Fix warning message for classic tokens. Add time prinout to help judge need for
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
jekyll-indico (0.4.3)
jekyll-indico (0.4.4)
jekyll (>= 3.8, < 5.0)

GEM
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll-indico/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ def to_files(folder)
private

# Run a block over each item in the downloaded results
def download_and_iterate(base_url, indico_id, **params, &block)
def download_and_iterate(base_url, indico_id, timeout: nil, **params, &block)
params[:pretty] = 'no'
uri = URI.join(base_url, "/export/categ/#{indico_id}.json")
uri.query = URI.encode_www_form(params)

req = Net::HTTP::Get.new(uri)
req.read_timeout = timeout if timeout
if ENV['INDICO_TOKEN']
req['Authorization'] = "Bearer #{ENV['INDICO_TOKEN']}"
elsif ENV['INDICO_SECRET_KEY'] || ENV['INDICO_API_KEY']
Expand Down
7 changes: 3 additions & 4 deletions lib/jekyll-indico/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ def generate(site)
@site = site
@cache_msg = @site.config.dig('indico', 'cache-command')

timeout = @site.config.dig('indico', 'timeout')
Net::HTTP.read_timeout = timeout if timeout

meeting_ids = @site.config.dig('indico', 'ids')
raise MissingIDs, 'indico: ids: MISSING from your config!' unless meeting_ids
raise MissingIDs, 'indico: ids: must be a hash!' unless meeting_ids.is_a?(Hash)
Expand All @@ -37,13 +34,15 @@ def collect_meeting(name, number)
data_path = @site.config.dig('indico', 'data') || 'indico'
@site.data[data_path] = {} unless @site.data.key? data_path

timeout = @site.config.dig('indico', 'timeout')

# Do nothing if already downloaded
return if @site.data[data_path].key? name

msg = @cache_msg ? " - run `#{@cache_msg}` to cache" : ''
print "Accessing Indico meeting API for #{name}:#{number}#{msg}"
time = Benchmark.realtime do
iris_meeting = Meetings.new(base_url, number)
iris_meeting = Meetings.new(base_url, number, timeout: timeout)
@site.data[data_path][name] = iris_meeting.dict
end
puts ", took #{time.round(1)} s"
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-indico/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module JekyllIndico
VERSION = '0.4.3'
VERSION = '0.4.4'
end

0 comments on commit c23c5c4

Please sign in to comment.