Skip to content

Commit f8dcc13

Browse files
authored
fix: make task arguments clear (GoogleCloudPlatform#7843)
1 parent 6f9f563 commit f8dcc13

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

appengine-java11/tasks/src/main/java/com/example/task/CreateTask.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
import com.google.cloud.tasks.v2.Task;
2525
import com.google.protobuf.ByteString;
2626
import com.google.protobuf.Timestamp;
27+
import java.io.IOException;
2728
import java.nio.charset.Charset;
2829
import java.time.Clock;
2930
import java.time.Instant;
3031

3132
public class CreateTask {
32-
public static void main(String... args) throws Exception {
33+
public static void main(String[] args) throws IOException {
34+
// TODO(developer): Replace these variables before running the sample.
35+
String projectId = "my-project-id";
36+
String queue = "my-appengine-queue";
37+
String location = "us-central1";
38+
String payload = "hello";
39+
int seconds = 0; // Scheduled delay for the task in seconds
40+
createTask(projectId, queue, location, payload, seconds);
41+
}
42+
43+
// This is an example snippet for showing best practices.
44+
public static void createTask(
45+
String projectId, String queueName, String location, String payload, int seconds)
46+
throws IOException {
3347
// Instantiates a client.
3448
try (CloudTasksClient client = CloudTasksClient.create()) {
35-
// Variables provided by system variables.
36-
String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
37-
String queueName = System.getenv("QUEUE_ID");
38-
String location = System.getenv("LOCATION_ID");
39-
// Optional variables.
40-
String payload = "hello";
41-
int seconds = 0; // Scheduled delay for the task in seconds
42-
4349
// Construct the fully qualified queue name.
4450
String queuePath = QueueName.of(projectId, location, queueName).toString();
4551

appengine-java11/tasks/src/test/java/com/example/task/CreateTaskIT.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import org.junit.After;
2525
import org.junit.Before;
2626
import org.junit.BeforeClass;
27-
import org.junit.Rule;
2827
import org.junit.Test;
29-
import org.junit.rules.Timeout;
3028
import org.junit.runner.RunWith;
3129
import org.junit.runners.JUnit4;
3230

@@ -64,7 +62,11 @@ public void tearDown() {
6462

6563
@Test
6664
public void testCreateTask() throws Exception {
67-
CreateTask.main();
65+
String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
66+
String queueName = System.getenv("QUEUE_ID");
67+
String location = System.getenv("LOCATION_ID");
68+
69+
CreateTask.createTask(projectId, queueName, location, "hello", 0);
6870
String got = bout.toString();
6971
assertThat(got).contains("Task created:");
7072
}

0 commit comments

Comments
 (0)