def Engine::start_feed_thread
ret = Thread.new do
File.open($config['grab_log_path'], $config['grab_log_mode']) do |log|
log.sync = true
log.puts "#{Time.now}: Starting grab log."
$log = 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.puts _('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
$log.puts "#{Time.now}: Waiting on \"#{th_title}\""
th.join($config['thread_reap_timeout'] || 2)
end
rescue Exception
$log.puts "Feed Thread Reap Error: \"#$!\"."
next
end
end
rescue
log.puts 'Feed Error: ' << $!.to_s
end
end
first_iteration = false
interval = $config['feed_sleep_interval']
$new_status = $config['msg_grab_done'] % [ $VERSION ]
if $config['use_manual_update']
log.puts "#{Time.now}: Done checking."
Thread::stop
else
Thread::list.each do |th|
if th && th.status && th.alive? && th['feed']
$log.puts "DEBUG: thread list: #{th['feed']['title']}"
end
end
log.puts "#{Time.now}: Done checking. Sleeping for #{interval}s."
sleep interval
end
end
end
end
ret
end