mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-23 20:45:07 +00:00
use google java formatter to avoid downloading eclipse during build
This commit is contained in:
@@ -1,37 +1,33 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.backend.service.db.DatabaseCleaningService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Singleton
|
||||
public class AutoMarkAsReadTask extends ScheduledTask {
|
||||
|
||||
private final DatabaseCleaningService cleaner;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
cleaner.autoMarkAsRead();
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
cleaner.autoMarkAsRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 30;
|
||||
}
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.commafeed.CommaFeedConstants;
|
||||
import com.commafeed.backend.dao.UnitOfWork;
|
||||
import com.commafeed.backend.dao.UserDAO;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.service.UserService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -19,43 +16,42 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class DemoAccountCleanupTask extends ScheduledTask {
|
||||
|
||||
private final CommaFeedConfiguration config;
|
||||
private final UnitOfWork unitOfWork;
|
||||
private final UserDAO userDAO;
|
||||
private final UserService userService;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final UnitOfWork unitOfWork;
|
||||
private final UserDAO userDAO;
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
if (!config.users().createDemoAccount()) {
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected void run() {
|
||||
if (!config.users().createDemoAccount()) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("recreating demo user account");
|
||||
unitOfWork.run(() -> {
|
||||
User demoUser = userDAO.findByName(CommaFeedConstants.USERNAME_DEMO);
|
||||
if (demoUser == null) {
|
||||
return;
|
||||
}
|
||||
log.info("recreating demo user account");
|
||||
unitOfWork.run(
|
||||
() -> {
|
||||
User demoUser = userDAO.findByName(CommaFeedConstants.USERNAME_DEMO);
|
||||
if (demoUser == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
userService.unregister(demoUser);
|
||||
userService.createDemoUser();
|
||||
});
|
||||
userService.unregister(demoUser);
|
||||
userService.createDemoUser();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
protected long getInitialDelay() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getInitialDelay() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getPeriod() {
|
||||
return getTimeUnit().convert(24, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
@Override
|
||||
protected long getPeriod() {
|
||||
return getTimeUnit().convert(24, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,38 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.commafeed.backend.service.db.DatabaseCleaningService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Singleton
|
||||
public class EntriesExceedingFeedCapacityCleanupTask extends ScheduledTask {
|
||||
|
||||
private final CommaFeedConfiguration config;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int maxFeedCapacity = config.database().cleanup().maxFeedCapacity();
|
||||
if (maxFeedCapacity > 0) {
|
||||
cleaner.cleanEntriesForFeedsExceedingCapacity(maxFeedCapacity);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
int maxFeedCapacity = config.database().cleanup().maxFeedCapacity();
|
||||
if (maxFeedCapacity > 0) {
|
||||
cleaner.cleanEntriesForFeedsExceedingCapacity(maxFeedCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 10;
|
||||
}
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,41 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.commafeed.backend.service.db.DatabaseCleaningService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Singleton
|
||||
public class OldEntriesCleanupTask extends ScheduledTask {
|
||||
|
||||
private final CommaFeedConfiguration config;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Duration entriesMaxAge = config.database().cleanup().entriesMaxAge();
|
||||
if (!entriesMaxAge.isZero()) {
|
||||
Instant threshold = Instant.now().minus(entriesMaxAge);
|
||||
cleaner.cleanEntriesOlderThan(threshold);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
Duration entriesMaxAge = config.database().cleanup().entriesMaxAge();
|
||||
if (!entriesMaxAge.isZero()) {
|
||||
Instant threshold = Instant.now().minus(entriesMaxAge);
|
||||
cleaner.cleanEntriesOlderThan(threshold);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,39 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.commafeed.backend.service.db.DatabaseCleaningService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Singleton
|
||||
public class OldStatusesCleanupTask extends ScheduledTask {
|
||||
|
||||
private final CommaFeedConfiguration config;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Instant threshold = config.database().cleanup().statusesInstantThreshold();
|
||||
if (threshold != null) {
|
||||
cleaner.cleanStatusesOlderThan(threshold);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
Instant threshold = config.database().cleanup().statusesInstantThreshold();
|
||||
if (threshold != null) {
|
||||
cleaner.cleanStatusesOlderThan(threshold);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 15;
|
||||
}
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,33 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.backend.service.db.DatabaseCleaningService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Singleton
|
||||
public class OrphanedContentsCleanupTask extends ScheduledTask {
|
||||
|
||||
private final DatabaseCleaningService cleaner;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
cleaner.cleanContentsWithoutEntries();
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
cleaner.cleanContentsWithoutEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 25;
|
||||
}
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,33 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.backend.service.db.DatabaseCleaningService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Singleton
|
||||
public class OrphanedFeedsCleanupTask extends ScheduledTask {
|
||||
|
||||
private final DatabaseCleaningService cleaner;
|
||||
private final DatabaseCleaningService cleaner;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
cleaner.cleanFeedsWithoutSubscriptions();
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
cleaner.cleanFeedsWithoutSubscriptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 20;
|
||||
}
|
||||
@Override
|
||||
public long getInitialDelay() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
@Override
|
||||
public long getPeriod() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,29 +2,34 @@ package com.commafeed.backend.task;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public abstract class ScheduledTask {
|
||||
protected abstract void run();
|
||||
protected abstract void run();
|
||||
|
||||
protected abstract long getInitialDelay();
|
||||
protected abstract long getInitialDelay();
|
||||
|
||||
protected abstract long getPeriod();
|
||||
protected abstract long getPeriod();
|
||||
|
||||
protected abstract TimeUnit getTimeUnit();
|
||||
protected abstract TimeUnit getTimeUnit();
|
||||
|
||||
public void register(ScheduledExecutorService executor) {
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
ScheduledTask.this.run();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
};
|
||||
log.debug("registering task {} for execution every {} {}, starting in {} {}", getClass().getSimpleName(), getPeriod(),
|
||||
getTimeUnit(), getInitialDelay(), getTimeUnit());
|
||||
executor.scheduleWithFixedDelay(runnable, getInitialDelay(), getPeriod(), getTimeUnit());
|
||||
}
|
||||
public void register(ScheduledExecutorService executor) {
|
||||
Runnable runnable =
|
||||
() -> {
|
||||
try {
|
||||
ScheduledTask.this.run();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
};
|
||||
log.debug(
|
||||
"registering task {} for execution every {} {}, starting in {} {}",
|
||||
getClass().getSimpleName(),
|
||||
getPeriod(),
|
||||
getTimeUnit(),
|
||||
getInitialDelay(),
|
||||
getTimeUnit());
|
||||
executor.scheduleWithFixedDelay(runnable, getInitialDelay(), getPeriod(), getTimeUnit());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,34 @@
|
||||
package com.commafeed.backend.task;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
|
||||
import io.quarkus.arc.All;
|
||||
import jakarta.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
public class TaskScheduler {
|
||||
|
||||
private final List<ScheduledTask> tasks;
|
||||
private final CommaFeedConfiguration config;
|
||||
private final List<ScheduledTask> tasks;
|
||||
private final CommaFeedConfiguration config;
|
||||
|
||||
private ScheduledExecutorService executor;
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
public TaskScheduler(@All List<ScheduledTask> tasks, CommaFeedConfiguration config) {
|
||||
this.tasks = tasks;
|
||||
this.config = config;
|
||||
}
|
||||
public TaskScheduler(@All List<ScheduledTask> tasks, CommaFeedConfiguration config) {
|
||||
this.tasks = tasks;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.executor = Executors.newScheduledThreadPool(tasks.size());
|
||||
this.tasks.forEach(task -> task.register(executor));
|
||||
}
|
||||
public void start() {
|
||||
this.executor = Executors.newScheduledThreadPool(tasks.size());
|
||||
this.tasks.forEach(task -> task.register(executor));
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
MoreExecutors.shutdownAndAwaitTermination(executor, config.shutdownTimeout());
|
||||
}
|
||||
public void stop() {
|
||||
MoreExecutors.shutdownAndAwaitTermination(executor, config.shutdownTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user