mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Create an injectable LockHandler
We create an injectable LockHandler that just calls the static Lock.executeWithLocks function. I'm not sure what's the correct place to put the LockHandler. I think model/server is only appropriate for the actual datastore lock. This is a "per request" lock, so maybe request/lock? ----------------------------- This is the initial step in adding the "lock implicitly released on request death" feature, but it's also useful on its own - easier to test Actions when we can use a fake lock. To keep this CL simple, we keep using the old Lock as is in most places. We just choose a single example to convert to LockHandler to showcase it. Converting all other uses will be in a subsequent CL. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=167357564
This commit is contained in:
parent
67276888d2
commit
978149e677
7 changed files with 85 additions and 17 deletions
|
@ -12,6 +12,7 @@ java_library(
|
|||
"//java/google/registry/model",
|
||||
"//java/google/registry/request",
|
||||
"//java/google/registry/request/auth",
|
||||
"//java/google/registry/request/lock",
|
||||
"//java/google/registry/util",
|
||||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"@com_google_api_client",
|
||||
|
|
|
@ -30,11 +30,11 @@ import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
|||
import com.google.common.base.Optional;
|
||||
import com.google.gdata.util.ServiceException;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.model.server.Lock;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.request.lock.LockHandler;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import java.io.IOException;
|
||||
|
@ -117,6 +117,7 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
|||
@Inject @Config("sheetLockTimeout") Duration timeout;
|
||||
@Inject @Config("sheetRegistrarId") Optional<String> idConfig;
|
||||
@Inject @Parameter("id") Optional<String> idParam;
|
||||
@Inject LockHandler lockHandler;
|
||||
@Inject SyncRegistrarsSheetAction() {}
|
||||
|
||||
@Override
|
||||
|
@ -146,7 +147,7 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
|||
return null;
|
||||
}
|
||||
};
|
||||
if (!Lock.executeWithLocks(runner, null, timeout, sheetLockName)) {
|
||||
if (!lockHandler.executeWithLocks(runner, null, timeout, sheetLockName)) {
|
||||
// If we fail to acquire the lock, it probably means lots of updates are happening at once, in
|
||||
// which case it should be safe to not bother. The task queue definition should *not* specify
|
||||
// max-concurrent-requests for this very reason.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue