lib/fluent/plugin/in_feedly.rb in fluent-plugin-feedly-0.0.2 vs lib/fluent/plugin/in_feedly.rb in fluent-plugin-feedly-0.0.3
- old
+ new
@@ -33,17 +33,15 @@
raise Fluent::ConfigError, "Feedly: fetch_count param (#{@fetch_count}) should be between 20 and 10000."
end
@client = Feedlr::Client.new(
oauth_access_token: @access_token,
- sandbox: @enable_sandbox,
+ sandbox: @enable_sandbox
)
end
def start
- @profile_id = @client.user_profile.id
- @state_store = StateStore.new(@state_file)
@thread = Thread.new(&method(:run))
end
def shutdown
Thread.kill(@thread)
@@ -52,38 +50,44 @@
def run
@initial_loop = true
loop do
begin
fetch
+ rescue Feedlr::Error::Unauthorized, Feedlr::Error::Forbidden => e
+ log.error "Feedly: unrecoverable error has occoured.", error: e.message, error_class: e.class
+ log.error_backtrace e.backtrace
+ break
rescue => e
- log.error "Feedly: unexpected error has occoured.", error: e.message, error_class: e.class
+ log.error "Feedly: error has occoured. trying to retry after #{@run_interval} seconds.", error: e.message, error_class: e.class
log.error_backtrace e.backtrace
sleep @run_interval
retry
end
sleep @run_interval
end
+ log.error "Feedly: stopped fetching process due to the previous error."
end
def fetch
+ @profile_id ||= @client.user_profile.id
+ @state_store ||= StateStore.new(@state_file)
@subscribe_categories.each do |category_name|
category_id = "user/#{@profile_id}/category/#{category_name}"
fetch_time_range = get_fetch_time_range
- loop {
+ loop do
request_option = { count: @fetch_count, continuation: get_continuation_id, newerThan: fetch_time_range }
cursor = @client.stream_entries_contents(category_id, request_option)
if cursor.items.nil?
- log.error "Feedly: unexpected error has occoured.", cursor: cursor
- break
+ return raise Feedlr::Error::ServerError, cursor
end
cursor.items.each do |item|
Engine.emit(@tag, Engine.now, item)
end
log.info "Feedly: fetched articles.", articles: cursor.items.size, request_option: request_option
set_continuation_id(cursor.continuation)
break if get_continuation_id.nil?
- }
+ end
end
end
def get_fetch_time_range
if @initial_loop
@@ -148,5 +152,6 @@
}
end
end
end
end
+