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