-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
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.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by system variables
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
appengine-java8/tasks/README.md
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
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.
There was a problem hiding this comment.
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()) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nix Newline
There was a problem hiding this comment.
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" \ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
* 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.