SUPPORT-9163: add more log for webDav
This commit is contained in:
parent
f93076d057
commit
407f489569
2 changed files with 9 additions and 2 deletions
|
|
@ -35,7 +35,6 @@ import ervu.model.webdav.Server;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
@ -46,7 +45,6 @@ import org.springframework.retry.annotation.Backoff;
|
||||||
import org.springframework.retry.annotation.Retryable;
|
import org.springframework.retry.annotation.Retryable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import ru.micord.ervu.security.esia.config.EsiaConfig;
|
|
||||||
import ru.micord.ervu.util.UrlUtils;
|
import ru.micord.ervu.util.UrlUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -215,8 +213,10 @@ public class WebDavClient {
|
||||||
@Retryable(value = {IOException.class}, backoff = @Backoff(delayExpression = "${webdav.retry.delay:500}"))
|
@Retryable(value = {IOException.class}, backoff = @Backoff(delayExpression = "${webdav.retry.delay:500}"))
|
||||||
public void deleteFilesOlderThan(long seconds, String url, String... extensions) throws IOException {
|
public void deleteFilesOlderThan(long seconds, String url, String... extensions) throws IOException {
|
||||||
Sardine sardine = initClient(username, password);
|
Sardine sardine = initClient(username, password);
|
||||||
|
AtomicInteger deletedCount = new AtomicInteger();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
LOGGER.info("Connecting to WebDAV at URL: {}", url);
|
||||||
List<DavResource> resources = sardine.list(url);
|
List<DavResource> resources = sardine.list(url);
|
||||||
resources.stream().filter(getPredicate(extensions))
|
resources.stream().filter(getPredicate(extensions))
|
||||||
.forEach(davResource -> {
|
.forEach(davResource -> {
|
||||||
|
|
@ -225,12 +225,16 @@ public class WebDavClient {
|
||||||
if (age > seconds * 1000) {
|
if (age > seconds * 1000) {
|
||||||
try {
|
try {
|
||||||
sardine.delete(url + davResource.getPath());
|
sardine.delete(url + davResource.getPath());
|
||||||
|
LOGGER.debug("Deleted file: {}", davResource.getName());
|
||||||
|
deletedCount.getAndIncrement();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
LOGGER.error("Failed to delete file {}", davResource.getName(), e);
|
LOGGER.error("Failed to delete file {}", davResource.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
LOGGER.info("Deleted {} old file(s) from WebDAV at URL: {}", deletedCount.get(), url);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,16 @@ public class WebDavSchedulerService {
|
||||||
@Scheduled(cron = "${webdav.cleanup.cron:0 0 0 * * *}")
|
@Scheduled(cron = "${webdav.cleanup.cron:0 0 0 * * *}")
|
||||||
@SchedulerLock(name = "webDavOldFilesCleaning")
|
@SchedulerLock(name = "webDavOldFilesCleaning")
|
||||||
public void deleteOldFiles() {
|
public void deleteOldFiles() {
|
||||||
|
LOGGER.info("Starting scheduled WebDAV cleanup job");
|
||||||
Arrays.stream(urls).forEach(url -> {
|
Arrays.stream(urls).forEach(url -> {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.info("Cleaning up WebDAV at URL: {}", url);
|
||||||
webDavClient.deleteFilesOlderThan(fileLifetime, url, fileExtensions);
|
webDavClient.deleteFilesOlderThan(fileLifetime, url, fileExtensions);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
LOGGER.error("Failed to clean up WebDAV on {}", url, e);
|
LOGGER.error("Failed to clean up WebDAV on {}", url, e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
LOGGER.info("Finished scheduled WebDAV cleanup job");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue