Add asynchronous scheduled actions to re-save entities

This is used in the domain transfer and delete flows, both of which are
asynchronous flows that have implicit default actions that will be taken at some
point in the future. This CL adds scheduled re-saves to take place soon after
those default actions would become effective, so that they can be re-saved
quickly if so.

Unfortunately the redemption grace period on our TLDs is 35 days, which exceeds
the 30 day maximum task ETA in App Engine, so these won't actually fire.  That's
fine though; the deletion is actually effective as of 5 days, and this is just
removing the grace period.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=201345274
This commit is contained in:
mcilwain 2018-06-20 06:48:24 -07:00 committed by Ben McIlwain
parent 87d1a1c2a3
commit 6f2e663b72
20 changed files with 573 additions and 103 deletions

View file

@ -51,6 +51,7 @@ import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.SessionMetadata;
import google.registry.flows.TransactionalFlow;
import google.registry.flows.annotations.ReportingSpec;
import google.registry.flows.async.AsyncFlowEnqueuer;
import google.registry.flows.custom.DomainDeleteFlowCustomLogic;
import google.registry.flows.custom.DomainDeleteFlowCustomLogic.AfterValidationParameters;
import google.registry.flows.custom.DomainDeleteFlowCustomLogic.BeforeResponseParameters;
@ -127,6 +128,7 @@ public final class DomainDeleteFlow implements TransactionalFlow {
@Inject HistoryEntry.Builder historyBuilder;
@Inject DnsQueue dnsQueue;
@Inject Trid trid;
@Inject AsyncFlowEnqueuer asyncFlowEnqueuer;
@Inject EppResponse.Builder responseBuilder;
@Inject DomainDeleteFlowCustomLogic flowCustomLogic;
@Inject DomainDeleteFlow() {}
@ -179,16 +181,19 @@ public final class DomainDeleteFlow implements TransactionalFlow {
builder.setDeletionTime(now).setStatusValues(null);
} else {
DateTime deletionTime = now.plus(durationUntilDelete);
DateTime redemptionTime = now.plus(redemptionGracePeriodLength);
PollMessage.OneTime deletePollMessage =
createDeletePollMessage(existingDomain, historyEntry, deletionTime);
entitiesToSave.add(deletePollMessage);
asyncFlowEnqueuer.enqueueAsyncResave(existingDomain, now, deletionTime);
asyncFlowEnqueuer.enqueueAsyncResave(existingDomain, now, redemptionTime);
builder.setDeletionTime(deletionTime)
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
// Clear out all old grace periods and add REDEMPTION, which does not include a key to a
// billing event because there isn't one for a domain delete.
.setGracePeriods(ImmutableSet.of(GracePeriod.createWithoutBillingEvent(
GracePeriodStatus.REDEMPTION,
now.plus(redemptionGracePeriodLength),
redemptionTime,
clientId)))
.setDeletePollMessage(Key.create(deletePollMessage));
// Note: The expiration time is unchanged, so if it's before the new deletion time, there will