mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 20:17:51 +02:00
Certain flows need to launch batched jobs. Logically this would mean that flows depend on batch. However, the current state of dependency was the other way around, and the reason for that was ResourceFlowUtils.java that had in it some utility functions that weren't used in the flows and were needed in the batch jobs. This CL removes these utility functions from the /flows/ directory, letting us reverse the dependency edge between flows/ and batch/ Part of this was moving the flows/async/ code into batch/ - which also makes sense because flows/async/ just "enqueued" tasks that would then be run by actions in batch/ It makes sense that the code that enqueues the tasks and the code that dequeues the tasks sit in the same library. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=228698761
114 lines
3.9 KiB
Java
114 lines
3.9 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.batch;
|
|
|
|
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
|
|
import static google.registry.batch.AsyncTaskEnqueuer.PARAM_REQUESTED_TIME;
|
|
import static google.registry.batch.AsyncTaskEnqueuer.PARAM_RESAVE_TIMES;
|
|
import static google.registry.batch.AsyncTaskEnqueuer.PARAM_RESOURCE_KEY;
|
|
import static google.registry.batch.AsyncTaskEnqueuer.QUEUE_ASYNC_ACTIONS;
|
|
import static google.registry.batch.AsyncTaskEnqueuer.QUEUE_ASYNC_DELETE;
|
|
import static google.registry.batch.AsyncTaskEnqueuer.QUEUE_ASYNC_HOST_RENAME;
|
|
import static google.registry.request.RequestParameters.extractOptionalBooleanParameter;
|
|
import static google.registry.request.RequestParameters.extractOptionalIntParameter;
|
|
import static google.registry.request.RequestParameters.extractOptionalParameter;
|
|
import static google.registry.request.RequestParameters.extractRequiredDatetimeParameter;
|
|
import static google.registry.request.RequestParameters.extractRequiredParameter;
|
|
import static google.registry.request.RequestParameters.extractSetOfDatetimeParameters;
|
|
|
|
import com.google.appengine.api.taskqueue.Queue;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.googlecode.objectify.Key;
|
|
import dagger.Module;
|
|
import dagger.Provides;
|
|
import google.registry.model.ImmutableObject;
|
|
import google.registry.request.Parameter;
|
|
import java.util.Optional;
|
|
import javax.inject.Named;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.joda.time.DateTime;
|
|
|
|
/**
|
|
* Dagger module for injecting common settings for batch actions.
|
|
*/
|
|
@Module
|
|
public class BatchModule {
|
|
|
|
@Provides
|
|
@Parameter("jobName")
|
|
static Optional<String> provideJobName(HttpServletRequest req) {
|
|
return extractOptionalParameter(req, "jobName");
|
|
}
|
|
|
|
@Provides
|
|
@Parameter("jobId")
|
|
static Optional<String> provideJobId(HttpServletRequest req) {
|
|
return extractOptionalParameter(req, "jobId");
|
|
}
|
|
|
|
@Provides
|
|
@Parameter("numJobsToDelete")
|
|
static Optional<Integer> provideNumJobsToDelete(HttpServletRequest req) {
|
|
return extractOptionalIntParameter(req, "numJobsToDelete");
|
|
}
|
|
|
|
@Provides
|
|
@Parameter("daysOld")
|
|
static Optional<Integer> provideDaysOld(HttpServletRequest req) {
|
|
return extractOptionalIntParameter(req, "daysOld");
|
|
}
|
|
|
|
@Provides
|
|
@Parameter("force")
|
|
static Optional<Boolean> provideForce(HttpServletRequest req) {
|
|
return extractOptionalBooleanParameter(req, "force");
|
|
}
|
|
|
|
@Provides
|
|
@Parameter(PARAM_RESOURCE_KEY)
|
|
static Key<ImmutableObject> provideResourceKey(HttpServletRequest req) {
|
|
return Key.create(extractRequiredParameter(req, PARAM_RESOURCE_KEY));
|
|
}
|
|
|
|
@Provides
|
|
@Parameter(PARAM_REQUESTED_TIME)
|
|
static DateTime provideRequestedTime(HttpServletRequest req) {
|
|
return extractRequiredDatetimeParameter(req, PARAM_REQUESTED_TIME);
|
|
}
|
|
|
|
@Provides
|
|
@Parameter(PARAM_RESAVE_TIMES)
|
|
static ImmutableSet<DateTime> provideResaveTimes(HttpServletRequest req) {
|
|
return extractSetOfDatetimeParameters(req, PARAM_RESAVE_TIMES);
|
|
}
|
|
|
|
@Provides
|
|
@Named(QUEUE_ASYNC_ACTIONS)
|
|
static Queue provideAsyncActionsPushQueue() {
|
|
return getQueue(QUEUE_ASYNC_ACTIONS);
|
|
}
|
|
|
|
@Provides
|
|
@Named(QUEUE_ASYNC_DELETE)
|
|
static Queue provideAsyncDeletePullQueue() {
|
|
return getQueue(QUEUE_ASYNC_DELETE);
|
|
}
|
|
|
|
@Provides
|
|
@Named(QUEUE_ASYNC_HOST_RENAME)
|
|
static Queue provideAsyncHostRenamePullQueue() {
|
|
return getQueue(QUEUE_ASYNC_HOST_RENAME);
|
|
}
|
|
}
|