Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cloud Tasks] Add HTTP push queue sample #1355

Merged
merged 13 commits into from
Apr 19, 2019
Merged

[Cloud Tasks] Add HTTP push queue sample #1355

merged 13 commits into from
Apr 19, 2019

Conversation

averikitsch
Copy link
Contributor

No description provided.

@averikitsch averikitsch requested review from dzlier-gcp and a team March 15, 2019 16:49
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 15, 2019
@averikitsch
Copy link
Contributor Author

Ping @dzlier-gcp, do you mind reviewing today or tomorrow?

@dzlier-gcp
Copy link
Member

Taking a look now.

import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class CreateHttpTask {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific directive to make this into a CLI sample instead of the new sample format? If it's just to keep it consistent with the CreateTask sample that already exists here, I don't think that's enough of a reason to do the whole CLI thing instead of following the new template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a quickstart, so It is nice to have the CLI to run it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to compile and run if the correct variables are added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the CLI.

// Instantiates a client.
try (CloudTasksClient client = CloudTasksClient.create()) {

// Variables provided by the CLI.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by system variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

String location = System.getenv("LOCATION_ID");
String url = System.getenv("URL");

// [START cloud_tasks_create_http_task]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the START tag above import statements so that the dependency paths are included when the code is hosted on c.g.c. (and move the END tag past close brackets as necessary).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -89,3 +92,18 @@ mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \
-Dexec.args="--project-id $GOOGLE_CLOUD_PROJECT \
--queue $QUEUE_ID --location $LOCATION_ID --payload hello --in-seconds 30"
```

### Using HTTP Push Queues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in line with not having the samples be a CLI, I think we're also not really including run instructions in the README for running the samples from the command line, as these code snippets are really for hosting on c.g.c documentation and not meant to be run directly by the users after cloning the whole repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


public class CreateHttpTask {

public static void main(String[] args) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the new sample template, this wouldn't be a main method, but rather a named one like "createHttpTask", and instead of getting the System env var values below, it would include those 4 things as named parameters. Then there would be commented out declarations of them below, e.g.

public static void createHttpTask(String projectId, String queueName, string location, string url) {
    // String projectId = "YOUR-PROJECT-ID";
    // etc

Then in your test file (unless there's a reason not to include a test with this sample, I don't have full context), you would get those input parameters from required environment variables and supply them in the method call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample will be a part of a quickstart as of right now; therefore I would like to keep the instructions in the README and the main method. I'm adding a bug for myself to update this complete sample after the launch to re-evaluate the CLI in CreateTask.java and add tests.

@averikitsch
Copy link
Contributor Author

In order to be consistent with other languages I moved the HTTP task sample to it's own directory.

@averikitsch
Copy link
Contributor Author

ping @dzlier-gcp (Sorry to bug you again, but trying to get this done by the EOW)

tasks/pom.xml Outdated
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.0.10</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the version of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


// Instantiates a client.
try (CloudTasksClient client = CloudTasksClient.create()) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix Newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -69,12 +69,15 @@ location is "us-central1").
export LOCATION_ID=<YOUR_ZONE>
```

### Using App Engine Queues
Create a task, targeted at the `/tasks/create` endpoint, with a payload specified:

```
mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these instructions still correct? It looks like you are using environment variables now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct. This readme is associated with the App Engine sample.

@averikitsch averikitsch merged commit df8ea9a into master Apr 19, 2019
@averikitsch averikitsch deleted the tasks branch April 19, 2019 19:20
averikitsch added a commit that referenced this pull request Oct 27, 2022
* Add HTTP sample

* Fix linting

* remove CLI

* Move http sample

* Fix pom.xml

* Update pom and linting

* Update tasks version
averikitsch added a commit that referenced this pull request Nov 1, 2022
* Add HTTP sample

* Fix linting

* remove CLI

* Move http sample

* Fix pom.xml

* Update pom and linting

* Update tasks version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants