def Engine::start_feed_thread
meth = 'Engine.start_feed_thread'
ret = Thread.new do
Engine::start_grab_log
first_iteration = true
loop do
if !first_iteration || $config['update_on_startup']
begin
threads = []
$config['feeds'].each do |the_feed|
threads << Thread::new(the_feed) do |feed|
Raggle::Engine::grab_feed(feed)
end
until Thread::list.size < ($config['max_threads'] || 60)
$log.debug(meth) { _('DEBUG: Waiting for threads') }
sleep 5
end
end
threads.each do |th|
begin
if th && th.status && th.alive?
th_title = th['feed'] ? th['feed']['title'] : th
th_msg = _('Waiting on "%s"')
$log.debug(meth) { th_msg % [th_title] }
th.join($config['thread_reap_timeout'] || 2)
end
rescue Exception
err_msg = _('Feed Thread Reap Error:')
$log.error(meth) { "#{err_msg} #$!" }
$log.debug(meth) {
bt = ($!.backtrace || []).join rescue ''
"#{err_msg} #$!: (backtrace): #{bt}"
}
next
end
end
rescue
err_msg = _('Feed Error: ')
$log.error(meth) { "#{err_msg} #$!" }
$log.debug(meth) {
bt = $!.backtrace.join rescue ''
"#{err_msg} #{$!} backtrace: #{bt}"
}
end
end
first_iteration = false
interval = $config['feed_sleep_interval']
$new_status = $config['msg_grab_done'] % [ $VERSION ]
if $config['use_manual_update']
$log.info(meth) { _('Done checking.') }
Thread::stop
else
Thread::list.each do |th|
if th && th.status && th.alive? && th['feed']
$log.debug(meth) { "threads: #{th['feed']['title']}" }
end
end
done_msg = _('Done checking. Sleeping for %d seconds.')
$log.info(meth) { done_msg % [interval] }
sleep interval
end
end
end
ret
end