mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
fix #19
This commit is contained in:
@@ -25,8 +25,8 @@ public class HttpGetter {
|
||||
HttpParams params = httpclient.getParams();
|
||||
HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES);
|
||||
HttpProtocolParams.setContentCharset(params, "UTF-8");
|
||||
HttpConnectionParams.setConnectionTimeout(params, 5000);
|
||||
HttpConnectionParams.setSoTimeout(params, 5000);
|
||||
HttpConnectionParams.setConnectionTimeout(params, 4000);
|
||||
HttpConnectionParams.setSoTimeout(params, 4000);
|
||||
|
||||
try {
|
||||
HttpGet httpget = new HttpGet(url);
|
||||
|
||||
@@ -64,11 +64,6 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
feed.setLastUpdated(Calendar.getInstance().getTime());
|
||||
feed.setMessage(null);
|
||||
feed.setErrorCount(0);
|
||||
feedService.update(feed);
|
||||
}
|
||||
|
||||
private void addFeedToEntry(FeedEntry entry, Feed feed) {
|
||||
|
||||
@@ -13,6 +13,13 @@ import com.uaihebert.model.EasyCriteria;
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedService extends GenericDAO<Feed> {
|
||||
|
||||
public List<Feed> findNextUpdatable(int count) {
|
||||
EasyCriteria<Feed> criteria = createCriteria();
|
||||
criteria.orderByAsc(MF.i(proxy().getLastUpdated()));
|
||||
criteria.setMaxResults(count);
|
||||
return criteria.getResultList();
|
||||
}
|
||||
|
||||
public Feed findByUrl(String url) {
|
||||
List<Feed> feeds = findByField(MF.i(proxy().getUrl()), url);
|
||||
return Iterables.getFirst(feeds, null);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.commafeed.backend.feeds;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Lock;
|
||||
import javax.ejb.LockType;
|
||||
import javax.ejb.Schedule;
|
||||
@@ -18,10 +20,13 @@ public class FeedTimer {
|
||||
@Inject
|
||||
FeedUpdater updater;
|
||||
|
||||
@Schedule(hour = "*", minute = "*", persistent = false)
|
||||
// every five seconds
|
||||
@Schedule(hour = "*", minute = "*", second = "*/5", persistent = false)
|
||||
@Lock(LockType.READ)
|
||||
private void timeout() {
|
||||
for (Feed feed : feedService.findAll()) {
|
||||
double count = feedService.getCount() * 5d / 60d;
|
||||
List<Feed> feeds = feedService.findNextUpdatable((int) count);
|
||||
for (Feed feed : feeds) {
|
||||
updater.update(feed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,8 @@ public class FeedUpdater {
|
||||
|
||||
@Asynchronous
|
||||
@Lock(LockType.READ)
|
||||
@AccessTimeout(value = 15, unit = TimeUnit.SECONDS)
|
||||
@AccessTimeout(value = 4, unit = TimeUnit.SECONDS)
|
||||
public void update(Feed feed) {
|
||||
|
||||
try {
|
||||
Feed fetchedFeed = fetcher.fetch(feed.getUrl());
|
||||
if (feed.getLink() == null) {
|
||||
@@ -44,12 +43,16 @@ public class FeedUpdater {
|
||||
}
|
||||
feedEntryService.updateEntries(feed.getUrl(),
|
||||
fetchedFeed.getEntries());
|
||||
|
||||
feed.setMessage(null);
|
||||
feed.setErrorCount(0);
|
||||
} catch (Exception e) {
|
||||
log.info("Unable to refresh feed " + feed.getUrl() + " : "
|
||||
+ e.getMessage());
|
||||
feed.setLastUpdated(Calendar.getInstance().getTime());
|
||||
feed.setMessage("Unable to refresh feed: " + e.getMessage());
|
||||
feed.setErrorCount(feed.getErrorCount() + 1);
|
||||
} finally {
|
||||
feed.setLastUpdated(Calendar.getInstance().getTime());
|
||||
feedService.update(feed);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user