forked from Archives/Athou_commafeed
refresh pubsubhubbub subscriptions every three days
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.commafeed.backend.feeds;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@@ -15,6 +17,7 @@ import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -188,13 +191,17 @@ public class FeedRefreshUpdater {
|
||||
|
||||
private void handlePubSub(final Feed feed) {
|
||||
FeedPushInfo info = feed.getPushInfo();
|
||||
if (info != null && info.isActive() == false) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
handler.subscribe(feed);
|
||||
}
|
||||
}.start();
|
||||
if (info != null) {
|
||||
Date lastPing = info.getLastPing();
|
||||
Date now = Calendar.getInstance().getTime();
|
||||
if (lastPing == null || lastPing.before(DateUtils.addDays(now, -3))) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
handler.subscribe(feed);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.commafeed.backend.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.annotations.Index;
|
||||
|
||||
@@ -25,7 +29,8 @@ public class FeedPushInfo extends AbstractModel {
|
||||
@Column(length = 2048, nullable = false)
|
||||
private String hub;
|
||||
|
||||
private boolean active;
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastPing;
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
@@ -51,12 +56,12 @@ public class FeedPushInfo extends AbstractModel {
|
||||
this.hub = hub;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
public Date getLastPing() {
|
||||
return lastPing;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
public void setLastPing(Date lastPing) {
|
||||
this.lastPing = lastPing;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ public class FeedPushInfoService {
|
||||
info.setFeed(feed);
|
||||
info.setHub(hub);
|
||||
info.setTopic(topic);
|
||||
info.setActive(false);
|
||||
feedPushInfoDAO.save(info);
|
||||
} else {
|
||||
info = infos.get(0);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -65,7 +66,7 @@ public class PubSubHubbubCallbackREST {
|
||||
for (FeedPushInfo info : infos) {
|
||||
log.debug("activated push notifications for {}",
|
||||
info.getTopic());
|
||||
info.setActive(true);
|
||||
info.setLastPing(Calendar.getInstance().getTime());
|
||||
}
|
||||
feedPushInfoDAO.update(infos);
|
||||
return Response.ok(challenge).build();
|
||||
|
||||
Reference in New Issue
Block a user