mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +02:00
Use cursor to track updating of registrar sheet
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=138221931
This commit is contained in:
parent
3a75486c72
commit
cef07f6bc5
9 changed files with 58 additions and 42 deletions
|
@ -618,17 +618,6 @@ public final class ConfigModule {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Amount of time between synchronizations of the Registrar spreadsheet.
|
||||
*
|
||||
* @see google.registry.export.sheet.SyncRegistrarsSheetAction
|
||||
*/
|
||||
@Provides
|
||||
@Config("sheetRegistrarInterval")
|
||||
public static Duration provideSheetRegistrarInterval() {
|
||||
return Duration.standardHours(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns SSH client connection and read timeout.
|
||||
*
|
||||
|
|
|
@ -21,6 +21,7 @@ java_library(
|
|||
"//third_party/java/joda_time",
|
||||
"//third_party/java/jsr305_annotations",
|
||||
"//third_party/java/jsr330_inject",
|
||||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"//third_party/java/servlet/servlet_api",
|
||||
"//java/google/registry/config",
|
||||
"//java/google/registry/model",
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
package google.registry.export.sheet;
|
||||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.ABUSE;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.ADMIN;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.BILLING;
|
||||
|
@ -22,6 +24,7 @@ import static google.registry.model.registrar.RegistrarContact.Type.LEGAL;
|
|||
import static google.registry.model.registrar.RegistrarContact.Type.MARKETING;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.TECH;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.WHOIS;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
|
@ -32,6 +35,8 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gdata.util.ServiceException;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.model.common.Cursor;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.RegistrarAddress;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
|
@ -41,10 +46,9 @@ import java.io.IOException;
|
|||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
/**
|
||||
* Class for synchronizing all {@link Registrar} datastore objects to a Google Spreadsheet.
|
||||
* Class for synchronizing all {@link Registrar} Datastore objects to a Google Spreadsheet.
|
||||
*
|
||||
* @see SyncRegistrarsSheetAction
|
||||
*/
|
||||
|
@ -54,11 +58,15 @@ class SyncRegistrarsSheet {
|
|||
@Inject SheetSynchronizer sheetSynchronizer;
|
||||
@Inject SyncRegistrarsSheet() {}
|
||||
|
||||
/** Returns true if a {@link Registrar} entity was modified in past {@code duration}. */
|
||||
boolean wasRegistrarsModifiedInLast(Duration duration) {
|
||||
DateTime watermark = clock.nowUtc().minus(duration);
|
||||
/**
|
||||
* Returns true if any {@link Registrar} entity was modified since the last time this task
|
||||
* successfully completed, as measured by a cursor.
|
||||
*/
|
||||
boolean wereRegistrarsModified() {
|
||||
Cursor cursor = ofy().load().key(Cursor.createGlobalKey(SYNC_REGISTRAR_SHEET)).now();
|
||||
DateTime lastUpdateTime = (cursor == null) ? START_OF_TIME : cursor.getCursorTime();
|
||||
for (Registrar registrar : Registrar.loadAll()) {
|
||||
if (DateTimeUtils.isAtOrAfter(registrar.getLastUpdateTime(), watermark)) {
|
||||
if (DateTimeUtils.isAtOrAfter(registrar.getLastUpdateTime(), lastUpdateTime)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +75,7 @@ class SyncRegistrarsSheet {
|
|||
|
||||
/** Performs the synchronization operation. */
|
||||
void run(String spreadsheetId) throws IOException, ServiceException {
|
||||
final DateTime executionTime = clock.nowUtc();
|
||||
sheetSynchronizer.synchronize(
|
||||
spreadsheetId,
|
||||
FluentIterable
|
||||
|
@ -167,6 +176,11 @@ class SyncRegistrarsSheet {
|
|||
}
|
||||
})
|
||||
.toList());
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(Cursor.createGlobal(SYNC_REGISTRAR_SHEET, executionTime));
|
||||
}});
|
||||
}
|
||||
|
||||
private static String convertContacts(
|
||||
|
|
|
@ -111,7 +111,6 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
|||
@Inject SyncRegistrarsSheet syncRegistrarsSheet;
|
||||
@Inject @Config("sheetLockTimeout") Duration timeout;
|
||||
@Inject @Config("sheetRegistrarId") Optional<String> idConfig;
|
||||
@Inject @Config("sheetRegistrarInterval") Duration interval;
|
||||
@Inject @Parameter("id") Optional<String> idParam;
|
||||
@Inject SyncRegistrarsSheetAction() {}
|
||||
|
||||
|
@ -123,8 +122,7 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
|||
return;
|
||||
}
|
||||
if (!idParam.isPresent()) {
|
||||
// TODO(b/19082368): Use a cursor.
|
||||
if (!syncRegistrarsSheet.wasRegistrarsModifiedInLast(interval)) {
|
||||
if (!syncRegistrarsSheet.wereRegistrarsModified()) {
|
||||
Result.NOTMODIFIED.send(response, null);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,14 @@ public class Cursor extends ImmutableObject {
|
|||
* for which Recurring billing events have been expanded (i.e. the inclusive first billing time
|
||||
* for the next expansion job).
|
||||
*/
|
||||
RECURRING_BILLING(EntityGroupRoot.class);
|
||||
RECURRING_BILLING(EntityGroupRoot.class),
|
||||
|
||||
/**
|
||||
* Cursor for {@link google.registry.export.sheet.SyncRegistrarsSheetAction}. The DateTime
|
||||
* stored is the last time that registrar changes were successfully synced to the sheet. If
|
||||
* there were no changes since the last time the action run, the cursor is not updated.
|
||||
*/
|
||||
SYNC_REGISTRAR_SHEET(EntityGroupRoot.class);
|
||||
|
||||
/** See the definition of scope on {@link #getScopeClass}. */
|
||||
private final Class<? extends ImmutableObject> scope;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue