Rename ManagedPeriodicWorkCache to ManagedPeriodicWorkLock

This commit is contained in:
Chris Eager 2021-06-24 17:10:46 -05:00 committed by Chris Eager
parent eac48a6617
commit 74ff491671
3 changed files with 8 additions and 8 deletions

View File

@ -34,7 +34,7 @@ public class DeletedAccountsTableCrawler extends ManagedPeriodicWork {
final List<DeletedAccountsDirectoryReconciler> reconcilers,
final FaultTolerantRedisCluster cluster) throws IOException {
super(new ManagedPeriodicWorkCache(ACTIVE_WORKER_KEY, cluster), WORKER_TTL, RUN_INTERVAL);
super(new ManagedPeriodicWorkLock(ACTIVE_WORKER_KEY, cluster), WORKER_TTL, RUN_INTERVAL);
this.deletedAccounts = deletedAccounts;
this.reconcilers = reconcilers;

View File

@ -16,7 +16,7 @@ public abstract class ManagedPeriodicWork implements Managed, Runnable {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final ManagedPeriodicWorkCache cache;
private final ManagedPeriodicWorkLock lock;
private final Duration workerTtl;
private final Duration runInterval;
private final String workerId;
@ -24,8 +24,8 @@ public abstract class ManagedPeriodicWork implements Managed, Runnable {
private final AtomicBoolean running = new AtomicBoolean(false);
private boolean finished;
public ManagedPeriodicWork(final ManagedPeriodicWorkCache cache, final Duration workerTtl, final Duration runInterval) {
this.cache = cache;
public ManagedPeriodicWork(final ManagedPeriodicWorkLock lock, final Duration workerTtl, final Duration runInterval) {
this.lock = lock;
this.workerTtl = workerTtl;
this.runInterval = runInterval;
this.workerId = UUID.randomUUID().toString();
@ -73,7 +73,7 @@ public abstract class ManagedPeriodicWork implements Managed, Runnable {
private void execute() {
if (cache.claimActiveWork(workerId, workerTtl)) {
if (lock.claimActiveWork(workerId, workerTtl)) {
try {
final long startTimeMs = System.currentTimeMillis();
@ -96,7 +96,7 @@ public abstract class ManagedPeriodicWork implements Managed, Runnable {
sleepWhileRunning(runInterval);
} finally {
cache.releaseActiveWork(workerId);
lock.releaseActiveWork(workerId);
}
}
}

View File

@ -12,14 +12,14 @@ import java.io.IOException;
import java.time.Duration;
import java.util.List;
public class ManagedPeriodicWorkCache {
public class ManagedPeriodicWorkLock {
private final String activeWorkerKey;
private final FaultTolerantRedisCluster cacheCluster;
private final ClusterLuaScript unlockClusterScript;
public ManagedPeriodicWorkCache(final String activeWorkerKey, final FaultTolerantRedisCluster cacheCluster) throws IOException {
public ManagedPeriodicWorkLock(final String activeWorkerKey, final FaultTolerantRedisCluster cacheCluster) throws IOException {
this.activeWorkerKey = activeWorkerKey;
this.cacheCluster = cacheCluster;
this.unlockClusterScript = ClusterLuaScript.fromResource(cacheCluster, "lua/periodic_worker/unlock.lua", ScriptOutputType.INTEGER);