Skip to content

Commit c3bebbe

Browse files
committed
2 parents aad4aff + cd9fe5b commit c3bebbe

19 files changed

+224
-302
lines changed

READONLY

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/google/src/files/201106159/depot

appengine-java8/tasks/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Google Cloud Tasks App Engine Queue Samples
2+
3+
Sample command-line program for interacting with the Cloud Tasks API
4+
using App Engine queues.
5+
6+
App Engine queues push tasks to an App Engine HTTP target. This directory
7+
contains both the App Engine app to deploy, as well as the snippets to run
8+
locally to push tasks to it, which could also be called on App Engine.
9+
10+
`CreateTask.java` is a simple command-line program to create
11+
tasks to be pushed to the App Engine app.
12+
13+
`TaskServlet.java` is the main App Engine app. This app serves as an endpoint to receive
14+
App Engine task attempts.
15+
16+
17+
## Initial Setup
18+
19+
* Set up a Google Cloud Project and enable billing.
20+
* Enable the
21+
[Cloud Tasks API](https://console.cloud.google.com/launcher/details/google/cloudtasks.googleapis.com).
22+
* Download and install the [Cloud SDK](https://cloud.google.com/sdk).
23+
* Download and install [Maven](http://maven.apache.org/install.html).
24+
25+
## Creating a queue
26+
27+
To create a queue using the Cloud SDK, use the following gcloud command:
28+
29+
```
30+
gcloud beta tasks queues create-app-engine-queue my-appengine-queue
31+
```
32+
33+
Note: A newly created queue will route to the default App Engine service and
34+
version unless configured to do otherwise.
35+
36+
## Deploying the App Engine app
37+
[Using Maven and the App Engine Plugin](https://cloud.google.com/appengine/docs/flexible/java/using-maven)
38+
& [Maven Plugin Goals and Parameters](https://cloud.google.com/appengine/docs/flexible/java/maven-reference)
39+
40+
### Running locally
41+
42+
```
43+
mvn appengine:run
44+
```
45+
### Deploying
46+
47+
```
48+
mvn appengine:deploy
49+
```
50+
51+
## Running the Sample
52+
53+
Set environment variables:
54+
55+
First, your project ID:
56+
57+
```
58+
export GOOGLE_CLOUD_PROJECT=<YOUR_PROJECT_ID>
59+
```
60+
61+
Then the queue ID, as specified at queue creation time. Queue IDs already
62+
created can be listed with `gcloud beta tasks queues list`.
63+
64+
```
65+
export QUEUE_ID=my-appengine-queue
66+
```
67+
68+
And finally the location ID, which can be discovered with
69+
`gcloud beta tasks queues describe $QUEUE_ID`, with the location embedded in
70+
the "name" value (for instance, if the name is
71+
"projects/my-project/locations/us-central1/queues/my-appengine-queue", then the
72+
location is "us-central1").
73+
74+
```
75+
export LOCATION_ID=<YOUR_ZONE>
76+
```
77+
78+
Create a task, targeted at the `/tasks/create` endpoint, with a payload specified:
79+
80+
```
81+
mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \
82+
-Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \
83+
--queue $QUEUE_ID --location $LOCATION_ID --payload hello"
84+
```
85+
86+
The App Engine app serves as a target for the push requests. It has an
87+
endpoint `/tasks/create` that reads the payload (i.e., the request body) of the
88+
HTTP POST request and logs it. The log output can be viewed with:
89+
90+
```
91+
gcloud app logs read
92+
```
93+
94+
Create a task that will be scheduled for a time in the future using the
95+
`--in-seconds` flag:
96+
97+
```
98+
mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \
99+
-Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \
100+
--queue $QUEUE_ID --location $LOCATION_ID --payload hello --in-seconds 30"
101+
```

appengine-java8/tasks/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Copyright 2018 Google LLC
3737
<properties>
3838
<maven.compiler.target>1.8</maven.compiler.target>
3939
<maven.compiler.source>1.8</maven.compiler.source>
40-
<maven-exec-plugin.version>1.6.0</maven-exec-plugin.version>
4140
</properties>
4241

4342
<dependencies>
@@ -86,7 +85,7 @@ Copyright 2018 Google LLC
8685
<plugin>
8786
<groupId>org.codehaus.mojo</groupId>
8887
<artifactId>exec-maven-plugin</artifactId>
89-
<version>${maven-exec-plugin.version}</version>
88+
<version>1.6.0</version>
9089
<configuration>
9190
<mainClass>com.example.task.CreateTask</mainClass>
9291
<cleanupDaemonThreads>false</cleanupDaemonThreads>

jobs/cjd_sample/src/main/java/com/google/samples/AutoCompleteSample.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,8 @@
2020
import com.google.api.services.jobs.v2.JobService.V2.Complete;
2121
import com.google.api.services.jobs.v2.model.Company;
2222
import com.google.api.services.jobs.v2.model.CompleteQueryResponse;
23-
import com.google.api.services.jobs.v2.model.CompletionResult;
24-
import com.google.api.services.jobs.v2.model.CreateJobRequest;
25-
import com.google.api.services.jobs.v2.model.HistogramFacets;
2623
import com.google.api.services.jobs.v2.model.Job;
27-
import com.google.api.services.jobs.v2.model.JobQuery;
28-
import com.google.api.services.jobs.v2.model.MatchingJob;
29-
import com.google.api.services.jobs.v2.model.RequestMetadata;
30-
import com.google.api.services.jobs.v2.model.SearchJobsRequest;
31-
import com.google.api.services.jobs.v2.model.SearchJobsResponse;
3224
import java.io.IOException;
33-
import java.util.ArrayList;
34-
import java.util.Arrays;
35-
import java.util.List;
3625

3726
/**
3827
* The samples in this file introduced how to do the auto complete, including:
@@ -43,7 +32,7 @@
4332
*/
4433
public final class AutoCompleteSample {
4534

46-
private static JobService jobService = JobServiceUtils.getJobService();
35+
private static JobService jobService = JobServiceQuickstart.getJobService();
4736

4837
//[START auto_complete_job_title]
4938

jobs/cjd_sample/src/main/java/com/google/samples/BasicCompanySample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
public final class BasicCompanySample {
4040

41-
private static JobService jobService = JobServiceUtils.getJobService();
41+
private static JobService jobService = JobServiceQuickstart.getJobService();
4242

4343
// [START basic_company]
4444

jobs/cjd_sample/src/main/java/com/google/samples/BasicJobSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*/
4343
public final class BasicJobSample {
4444

45-
private static JobService jobService = JobServiceUtils.getJobService();
45+
private static JobService jobService = JobServiceQuickstart.getJobService();
4646

4747
// [START basic_job]
4848

jobs/cjd_sample/src/main/java/com/google/samples/BatchOperationSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
public final class BatchOperationSample {
4747

48-
private static JobService jobService = JobServiceUtils.getJobService();
48+
private static JobService jobService = JobServiceQuickstart.getJobService();
4949

5050
// [START batch_job_create]
5151
public static List<Job> batchCreateJobs(String companyName) throws IOException {

jobs/cjd_sample/src/main/java/com/google/samples/CommuteSearchSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
public final class CommuteSearchSample {
3838

39-
private static JobService jobService = JobServiceUtils.getJobService();
39+
private static JobService jobService = JobServiceQuickstart.getJobService();
4040

4141
// [START commute_search]
4242

jobs/cjd_sample/src/main/java/com/google/samples/CustomAttributeSample.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818

1919
import com.google.api.services.jobs.v2.JobService;
2020
import com.google.api.services.jobs.v2.model.Company;
21-
import com.google.api.services.jobs.v2.model.CreateJobRequest;
2221
import com.google.api.services.jobs.v2.model.CustomAttribute;
23-
import com.google.api.services.jobs.v2.model.CustomField;
24-
import com.google.api.services.jobs.v2.model.CustomFieldFilter;
2522
import com.google.api.services.jobs.v2.model.Job;
26-
import com.google.api.services.jobs.v2.model.JobFilters;
2723
import com.google.api.services.jobs.v2.model.JobQuery;
2824
import com.google.api.services.jobs.v2.model.RequestMetadata;
2925
import com.google.api.services.jobs.v2.model.SearchJobsRequest;
@@ -44,7 +40,7 @@
4440
*/
4541
public final class CustomAttributeSample {
4642

47-
private static JobService jobService = JobServiceUtils.getJobService();
43+
private static JobService jobService = JobServiceQuickstart.getJobService();
4844

4945
// [START custom_attribute_job]
5046

0 commit comments

Comments
 (0)