mirror of https://github.com/zlatinb/muwire
store last update attempt and do not retry active feeds
parent
8f710e68c2
commit
c3d0dce281
|
@ -1,6 +1,6 @@
|
||||||
package com.muwire.core.filefeeds
|
package com.muwire.core.filefeeds
|
||||||
|
|
||||||
import java.lang.System.Logger.Level
|
import java.util.logging.Level
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.concurrent.Executor
|
import java.util.concurrent.Executor
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
|
@ -64,6 +64,7 @@ class FeedClient {
|
||||||
Endpoint endpoint = null
|
Endpoint endpoint = null
|
||||||
try {
|
try {
|
||||||
eventBus.publish(new FeedFetchEvent(host : feed.getPublisher(), status : FeedFetchStatus.CONNECTING))
|
eventBus.publish(new FeedFetchEvent(host : feed.getPublisher(), status : FeedFetchStatus.CONNECTING))
|
||||||
|
feed.setLastUpdateAttempt(System.currentTimeMillis())
|
||||||
endpoint = connector.connect(feed.getPublisher().getDestination())
|
endpoint = connector.connect(feed.getPublisher().getDestination())
|
||||||
OutputStream os = endpoint.getOutputStream()
|
OutputStream os = endpoint.getOutputStream()
|
||||||
os.write("FEED\r\n".getBytes(StandardCharsets.US_ASCII))
|
os.write("FEED\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
|
|
|
@ -54,7 +54,8 @@ class FeedManager {
|
||||||
public List<Feed> getFeedsToUpdate() {
|
public List<Feed> getFeedsToUpdate() {
|
||||||
long now = System.currentTimeMillis()
|
long now = System.currentTimeMillis()
|
||||||
feeds.values().stream().
|
feeds.values().stream().
|
||||||
filter({Feed f -> f.getLastUpdated() + f.getUpdateInterval() <= now})
|
filter({Feed f -> !f.getStatus().isActive()}).
|
||||||
|
filter({Feed f -> f.getLastUpdateAttempt() + f.getUpdateInterval() <= now})
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +79,10 @@ class FeedManager {
|
||||||
Feed feed = new Feed(publisher)
|
Feed feed = new Feed(publisher)
|
||||||
feed.setUpdateInterval(parsed.updateInterval)
|
feed.setUpdateInterval(parsed.updateInterval)
|
||||||
feed.setLastUpdated(parsed.lastUpdated)
|
feed.setLastUpdated(parsed.lastUpdated)
|
||||||
|
feed.setLastUpdateAttempt(parsed.lastUpdateAttempt)
|
||||||
feed.setItemsToKeep(parsed.itemsToKeep)
|
feed.setItemsToKeep(parsed.itemsToKeep)
|
||||||
feed.setAutoDownload(parsed.autoDownload)
|
feed.setAutoDownload(parsed.autoDownload)
|
||||||
|
feed.setSequential(parsed.sequential)
|
||||||
|
|
||||||
feed.setStatus(FeedFetchStatus.IDLE)
|
feed.setStatus(FeedFetchStatus.IDLE)
|
||||||
|
|
||||||
|
@ -122,18 +125,21 @@ class FeedManager {
|
||||||
|
|
||||||
Feed feed = feeds.get(e.host)
|
Feed feed = feeds.get(e.host)
|
||||||
if (feed == null) {
|
if (feed == null) {
|
||||||
log.severe("Finished fetching non-existent feed " + e.host.getHumanReadableName())
|
log.severe("Fetching non-existent feed " + e.host.getHumanReadableName())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
feed.setStatus(e.status)
|
feed.setStatus(e.status)
|
||||||
|
|
||||||
if (e.status != FeedFetchStatus.FINISHED)
|
if (e.status.isActive())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if (e.status == FeedFetchStatus.FINISHED) {
|
||||||
feed.setStatus(FeedFetchStatus.IDLE)
|
feed.setStatus(FeedFetchStatus.IDLE)
|
||||||
feed.setLastUpdated(e.getTimestamp())
|
feed.setLastUpdated(e.getTimestamp())
|
||||||
// save feed items, then save feed
|
}
|
||||||
|
// save feed items, then save feed. This will save partial fetches too
|
||||||
|
// which is ok because the items are stored in a Set
|
||||||
persister.submit({saveFeedItems(e.host)} as Runnable)
|
persister.submit({saveFeedItems(e.host)} as Runnable)
|
||||||
persister.submit({saveFeedMetadata(feed)} as Runnable)
|
persister.submit({saveFeedMetadata(feed)} as Runnable)
|
||||||
}
|
}
|
||||||
|
@ -192,6 +198,8 @@ class FeedManager {
|
||||||
json.lastUpdated = feed.getLastUpdated()
|
json.lastUpdated = feed.getLastUpdated()
|
||||||
json.updateInterval = feed.getUpdateInterval()
|
json.updateInterval = feed.getUpdateInterval()
|
||||||
json.autoDownload = feed.isAutoDownload()
|
json.autoDownload = feed.isAutoDownload()
|
||||||
|
json.sequential = feed.isSequential()
|
||||||
|
json.lastUpdateAttempt = feed.getLastUpdateAttempt()
|
||||||
json = JsonOutput.toJson(json)
|
json = JsonOutput.toJson(json)
|
||||||
writer.println(json)
|
writer.println(json)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ public class Feed {
|
||||||
|
|
||||||
private int updateInterval;
|
private int updateInterval;
|
||||||
private long lastUpdated;
|
private long lastUpdated;
|
||||||
|
private volatile long lastUpdateAttempt;
|
||||||
private int itemsToKeep;
|
private int itemsToKeep;
|
||||||
private boolean autoDownload;
|
private boolean autoDownload;
|
||||||
private boolean sequential;
|
private boolean sequential;
|
||||||
|
@ -69,4 +70,12 @@ public class Feed {
|
||||||
public boolean isSequential() {
|
public boolean isSequential() {
|
||||||
return sequential;
|
return sequential;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastUpdateAttempt(long lastUpdateAttempt) {
|
||||||
|
this.lastUpdateAttempt = lastUpdateAttempt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastUpdateAttempt() {
|
||||||
|
return lastUpdateAttempt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue