-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
246 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM openjdk:8-jre-alpine | ||
|
||
WORKDIR /pnd | ||
COPY . /pnd | ||
|
||
RUN echo "Asia/Shanghai" > /etc/timezone | ||
|
||
EXPOSE 8989 | ||
VOLUME /pnd/data | ||
ENTRYPOINT ["bin/startup.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
#!/usr/bin/env bash | ||
#!/usr/bin/env sh | ||
|
||
PND_HOME=`cd $(dirname $0)/..; pwd` | ||
|
||
JAVA_OPTS="${JAVA_OPTS} -Dpnd.home=${PND_HOME}" | ||
JAVA_OPTS="${JAVA_OPTS} -jar "${PND_HOME}/lib/pnd-web.jar"" | ||
JAVA_OPTS="${JAVA_OPTS} --spring.config.location=${PND_HOME}/conf/application.properties" | ||
|
||
if [ ! -d "${PND_HOME}/logs" ]; then | ||
mkdir ${PND_HOME}/logs | ||
if [ ! -d "${PND_HOME}/data/logs" ]; then | ||
mkdir -p ${PND_HOME}/data/logs | ||
fi | ||
|
||
#echo "nohup java ${JAVA_OPTS} > ${PND_HOME}/logs/pnd-start.log 2>&1 &" | ||
#nohup java ${JAVA_OPTS} > ${PND_HOME}/logs/pnd-start.log 2>&1 & | ||
#nohup java ${JAVA_OPTS} > ${PND_HOME}/data/logs/pnd-start.log 2>&1 < /dev/null | ||
java ${JAVA_OPTS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
web/src/main/java/site/bitinit/pnd/web/config/Scheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package site.bitinit.pnd.web.config; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.support.TransactionTemplate; | ||
import site.bitinit.pnd.web.dao.ResourceDao; | ||
import site.bitinit.pnd.web.model.PndResource; | ||
import site.bitinit.pnd.web.utils.PathUtils; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author: john | ||
* @date: 2019/5/2 | ||
*/ | ||
@Component | ||
public class Scheduler { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(Scheduler.class); | ||
|
||
@Autowired | ||
private PathUtils pathUtils; | ||
@Autowired | ||
private ResourceDao resourceDao; | ||
@Autowired | ||
private TransactionTemplate transactionTemplate; | ||
|
||
/** | ||
* 每天凌晨 2 点执行脏数据清理 | ||
*/ | ||
@Scheduled(cron = "0 0 2 * * ?") | ||
public void clearDirtyData(){ | ||
cleanResourceFile(cleanResourceTable()); | ||
} | ||
|
||
/** | ||
* 若清除资源表数据成功,再清理脏文件 | ||
* @param resources | ||
*/ | ||
private void cleanResourceFile(List<PndResource> resources) { | ||
resources.stream() | ||
.filter(p -> shouldDelete(p)) | ||
.forEach(resource -> { | ||
String subPath = resource.getPath() + File.separator + resource.getUuid(); | ||
String pathStr = pathUtils.getResourceAbsolutionPath(subPath); | ||
|
||
File file = new File(pathStr); | ||
if (file.exists()){ | ||
file.delete(); | ||
logger.info("clear resource {} success!", resource.getUuid()); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* 先通过事务清理资源表无效数据 | ||
* @return | ||
*/ | ||
private List<PndResource> cleanResourceTable() { | ||
return transactionTemplate.execute(transactionStatus -> { | ||
List<PndResource> pndResources = resourceDao.findDirtyResources(); | ||
List<Long> deleteIds = new ArrayList<>(); | ||
pndResources.stream() | ||
.filter(p -> shouldDelete(p)) | ||
.forEach(resource -> { | ||
deleteIds.add(resource.getId()); | ||
}); | ||
resourceDao.deleteBatch(deleteIds); | ||
return pndResources; | ||
}); | ||
} | ||
|
||
private boolean shouldDelete(PndResource resource){ | ||
if (System.currentTimeMillis() - resource.getGmtModified() >= RESOURCE_CLEAN_INTERVAL_TIME | ||
|| resource.getLink() == 0){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* 间隔时间 6h | ||
*/ | ||
private static final long RESOURCE_CLEAN_INTERVAL_TIME = 6 * 3600 * 1000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.