diff options
author | lnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972> | 2006-02-09 17:22:31 +0000 |
---|---|---|
committer | lnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972> | 2006-02-09 17:22:31 +0000 |
commit | 07202f62da21ecf978496f4bec7f97522f2fbe75 (patch) | |
tree | c563cfd449a262dc09932b45225e248c32f7502f /lib/feed2imap | |
parent | fc53a6dca11ba46317deead9e3d308305c06b6f5 (diff) | |
download | feed2imap-07202f62da21ecf978496f4bec7f97522f2fbe75.tar.gz feed2imap-07202f62da21ecf978496f4bec7f97522f2fbe75.tar.bz2 feed2imap-07202f62da21ecf978496f4bec7f97522f2fbe75.zip |
cleaned up the threaded code.
git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@80 f70e237a-67f3-0310-a06c-d2b8a7116972
Diffstat (limited to '')
-rw-r--r-- | lib/feed2imap/feed2imap.rb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb index b0eff19..a8fd1fb 100644 --- a/lib/feed2imap/feed2imap.rb +++ b/lib/feed2imap/feed2imap.rb @@ -99,28 +99,37 @@ class Feed2Imap end # for each feed, fetch, upload to IMAP and cache @logger.info("Fetching feeds") - loggermon = Mutex::new ths = [] + mutex = Mutex::new @config.feeds.each do |f| ths << Thread::new do url = f.url begin + mutex.lock lastcheck = @cache.get_last_check(f.name) if f.needfetch(lastcheck) - f.body = HTTPFetcher::fetch(f.url, @cache.get_last_check(f.name)) + mutex.unlock + s = HTTPFetcher::fetch(f.url, @cache.get_last_check(f.name)) + mutex.lock + f.body = s @cache.set_last_check(f.name, Time::now) end + mutex.unlock # dump if requested - if @config.dumpdir and f.body - fname = @config.dumpdir + '/' + f.name + '-' + Time::now.xmlschema - File::open(fname, 'w') { |file| file.puts f.body } + if @config.dumpdir + mutex.synchronize do + if f.body + fname = @config.dumpdir + '/' + f.name + '-' + Time::now.xmlschema + File::open(fname, 'w') { |file| file.puts f.body } + end + end end rescue Timeout::Error - loggermon.synchronize do + mutex.synchronize do @logger.fatal("Timeout::Error while fetching #{url}: #{$!}") end rescue - loggermon.synchronize do + mutex.synchronize do @logger.fatal("Error while fetching #{url}: #{$!}") end end |