[Cloud Tasks] Add HTTP push queue sample#1355
Conversation
|
Ping @dzlier-gcp, do you mind reviewing today or tomorrow? |
|
Taking a look now. |
| import org.apache.commons.cli.Options; | ||
| import org.apache.commons.cli.ParseException; | ||
|
|
||
| public class CreateHttpTask { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is a quickstart, so It is nice to have the CLI to run it.
There was a problem hiding this comment.
Is there an easy way to compile and run if the correct variables are added?
There was a problem hiding this comment.
I removed the CLI.
| // Instantiates a client. | ||
| try (CloudTasksClient client = CloudTasksClient.create()) { | ||
|
|
||
| // Variables provided by the CLI. |
| String location = System.getenv("LOCATION_ID"); | ||
| String url = System.getenv("URL"); | ||
|
|
||
| // [START cloud_tasks_create_http_task] |
There was a problem hiding this comment.
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).
appengine-java8/tasks/README.md
Outdated
| --queue $QUEUE_ID --location $LOCATION_ID --payload hello --in-seconds 30" | ||
| ``` | ||
|
|
||
| ### Using HTTP Push Queues |
There was a problem hiding this comment.
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.
|
|
||
| public class CreateHttpTask { | ||
|
|
||
| public static void main(String[] args) throws Exception { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
In order to be consistent with other languages I moved the HTTP task sample to it's own directory. |
|
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> |
There was a problem hiding this comment.
Don't forget to update the version of this.
|
|
||
| // Instantiates a client. | ||
| try (CloudTasksClient client = CloudTasksClient.create()) { | ||
|
|
| Create a task, targeted at the `/tasks/create` endpoint, with a payload specified: | ||
|
|
||
| ``` | ||
| mvn exec:java -Dexec.mainClass="com.example.task.CreateTask" \ |
There was a problem hiding this comment.
Are these instructions still correct? It looks like you are using environment variables now
There was a problem hiding this comment.
This is correct. This readme is associated with the App Engine sample.
* Add HTTP sample * Fix linting * remove CLI * Move http sample * Fix pom.xml * Update pom and linting * Update tasks version
* Add HTTP sample * Fix linting * remove CLI * Move http sample * Fix pom.xml * Update pom and linting * Update tasks version
No description provided.