This commit is contained in:
Athou
2013-04-09 11:50:21 +02:00
parent 7c3d299805
commit 71499b5ed0
5 changed files with 22 additions and 12 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}