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