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

Add task create & lease/acknowledge sample. #1153

Merged
merged 3 commits into from
Jul 14, 2018

Conversation

dzlier-gcp
Copy link
Member

Still working on the appengine version, but thought I would create the pull request now so reviews can start, since we were wanting this done by EOD.

I do not have a README currently because the content seems copied from the documentation at https://cloud.google.com/tasks/docs/quickstart-pull, which someone else will be working on this weekend. I will grab it from there and pull it down when it is done.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Jul 13, 2018
@dzlier-gcp dzlier-gcp force-pushed the master branch 6 times, most recently from bd33182 to a8ea5c3 Compare July 13, 2018 22:31
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Jul 13, 2018
@kurtisvg kurtisvg added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 14, 2018
.build();

public static void main(String... args) throws Exception {
// [START cloud_tasks_appengine_create_task]
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that you want the region tag to start here? It feels like most of the command line parsing isn't relevant enough that we want to link to it from elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure, but I also wanted to include enough context to understand what was happening. I don't know if these tags are used in the documentation, I was just copying them from the python sample. But I don't mind moving it.

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
log.info("Received task request: " + req.getServletPath());
if (req.getParameter("payload") != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be a good idea to add a line of logging for when the payload is null - that way if the user forgets to set a payload the endpoint will still logged that it was triggered.

Copy link
Member Author

Choose a reason for hiding this comment

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

These log statements were actually just for my debugging purposes initially, but yeah I can add one for a null payload. Warning level probably, since it doesn't affect the execution?

Copy link
Contributor

Choose a reason for hiding this comment

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

Typically logging is debug < info < warning < critical, so using ' debug' or 'info' is probably typical (but I don't think it makes a big difference for a smaller application).

tasks/pom.xml Outdated
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
</plugin>
<plugin>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is building the jar with dependencies required for deployment? If not, can we remove this section?

// [START cloud_tasks_lease_and_acknowledge_task]
private static void pullAndAckTask(String projectId, String queueName, String location) {
try (CloudTasksClient client = CloudTasksClient.create()) {
LeaseTasksRequest.Builder reqBuilder = LeaseTasksRequest.newBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason you are passing a builder instead of just the request?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not, on line 148 it passes reqBuilder.build()

Copy link
Member Author

Choose a reason for hiding this comment

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

Or do you mean declaring it locally as a request instead of a builder? If I'm taking the Ack request out into a var below, I'll do the same here for consistency.

Copy link
Contributor

@kurtisvg kurtisvg Jul 14, 2018

Choose a reason for hiding this comment

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

Yup that's what I meant - typically the builder pattern is a replacement for new, so it seems weird to trigger the build there. Looks good now.

}
Task task = response.getTasksList().get(0);
System.out.println("Leased task: " + task.getName());
client.acknowledgeTask(AcknowledgeTaskRequest
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about building the AcknowledgeTaskRequest before the function and passing it in? I think it increases readability and makes it more obvious what the function requires.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that's fine.

@dzlier-gcp
Copy link
Member Author

Requested changes done.

@dzlier-gcp dzlier-gcp merged commit a977aec into GoogleCloudPlatform:master Jul 14, 2018
averikitsch pushed a commit that referenced this pull request Oct 27, 2022
* Add task create & lease/acknowledge sample.

* Add Appengine Queue Tasks sample.
averikitsch pushed a commit that referenced this pull request Nov 1, 2022
* Add task create & lease/acknowledge sample.

* Add Appengine Queue Tasks sample.
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. do not merge Indicates a pull request not ready for merge, due to either quality or timing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants