일괄 작업 만들기

이 문서에서는 서버 환경에서 일괄 작업을 만드는 방법을 보여줍니다. 스테이트리스(Stateless) 컨테이너를 실행하는 할 일 만들기에 관한 자세한 내용은 다음을 참고하세요.

일괄로 태스크를 만들기 위한 태스크 필드

일괄로 작업을 만들 때 requests의 각 CreateTasksRequest 요소 단일 작업에 대한 CreateTask 요청과 동일한 유효성 검사 규칙을 전달해야 합니다. parentheader 필드는 선택사항입니다. 설정된 경우 최상위 수준의 해당 필드와 동일해야 합니다. BatchCreateTasksRequest

자세한 내용은 BatchCreateTasks의 API 참조 문서를 확인하세요. (gRPC 또는 REST용)

필수 일괄 필드

필드
요청 Array<CreateTasksRequest>

일괄 태스크 필드(선택사항)

필드
헤더 DeliveryRequestHeader

태스크 배치 만들기

다음 예시는 수령 및 배송 작업을 모두 만드는 방법을 보여줍니다. Java gRPC 라이브러리 사용 또는 BatchCreateTask

gRPC

static final String PROJECT_ID = "my-delivery-co-gcp-project";

DeliveryServiceBlockingStub deliveryService =
  DeliveryServiceGrpc.newBlockingStub(channel);

// Delivery Task settings
Task deliveryTask = Task.newBuilder()
  .setType(Task.Type.DELIVERY)
  .setState(Task.State.OPEN)
  .setTrackingId("delivery-tracking-id")
  .setPlannedLocation(               // Grand Indonesia East Mall
    LocationInfo.newBuilder().setPoint(
      LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))
  .setTaskDuration(
    Duration.newBuilder().setSeconds(2 * 60))
  .build();

// Delivery Task request
CreateTaskRequest createDeliveryTaskRequest =
  CreateTaskRequest.newBuilder()  // No need for the header or parent fields
      .setTaskId("task-8312508")  // Task ID assigned by the Provider
      .setTask(deliveryTask)      // Initial state
      .build();

// Pickup Task settings
Task pickupTask = Task.newBuilder()
  .setType(Task.Type.PICKUP)
  .setState(Task.State.OPEN)
  .setTrackingId("pickup-tracking-id")
  .setPlannedLocation(               // Grand Indonesia East Mall
    LocationInfo.newBuilder().setPoint(
      LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))
  .setTaskDuration(
    Duration.newBuilder().setSeconds(2 * 60))
  .build();

// Pickup Task request
CreateTaskRequest createPickupTaskRequest =
  CreateTaskRequest.newBuilder()  // No need for the header or parent fields
      .setTaskId("task-8241890")  // Task ID assigned by the Provider
      .setTask(pickupTask)        // Initial state
      .build();

// Batch Create Tasks settings
String parent = "providers/" + PROJECT_ID;

// Batch Create Tasks request
BatchCreateTasksRequest batchCreateTasksRequest =
  BatchCreateTasksRequest.newBuilder()
      .setParent(parent)
      .addRequests(createDeliveryTaskRequest)
      .addRequests(createPickupTaskRequest)
      .build();

// Error handling
// If Fleet Engine does not have any task(s) with these task ID(s) and the
// credentials of the requestor pass, the service creates the task(s)
// successfully.

try {
  BatchCreateTasksResponse createdTasks = deliveryService.batchCreateTasks(
    batchCreateTasksRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case ALREADY_EXISTS:
      break;
    case PERMISSION_DENIED:
      break;
  }
  return;
}

REST

서버 환경에서 전송 및 수령 작업을 만들려면 BatchCreateTasks에 대한 HTTP REST 호출:

POST https://fleetengine.googleapis.com/v1/providers/<project_id>/batchCreate

&lt;id&gt;는 작업의 고유 식별자입니다.

요청 헤더에는 값이 있는 Authorization 필드가 있어야 합니다. Bearer <token> - 서버에서 <token>을 가져옴 서비스 계정 역할JSON 웹 토큰.

요청 본문에는 BatchCreateTasksRequest 항목이 포함되어야 합니다.

curl 명령어 예시:

# Set $JWT, $PROJECT_ID, $DELIVERY_TRACKING_ID, $DELIVERY_TASK_ID,
# $PICKUP_TRACKING_ID, and $PICKUP_TASK_ID in the local environment
curl -X POST "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks:batchCreate" \
 -H "Content-type: application/json" \
 -H "Authorization: Bearer ${JWT}" \
 --data-binary @- << EOM
{
 "requests" : [
   {
     "taskId": "${DELIVERY_TASK_ID}",
     "task" : {
       "type": "DELIVERY",
       "state": "OPEN",
       "trackingId": "${DELIVERY_TRACKING_ID}",
       "plannedLocation": {
         "point": {
             "latitude": -6.195139,
             "longitude": 106.820826
         }
       },
       "taskDuration": "90s"
     }
   },
   {
     "taskId": "${PICKUP_TASK_ID}",
     "task" : {
       "type": "PICKUP",
       "state": "OPEN",
       "trackingId": "${PICKUP_TRACKING_ID}",
       "plannedLocation": {
         "point": {
             "latitude": -6.195139,
             "longitude": 106.820826
         }
       },
       "taskDuration": "90s"
     }
   }
 ]
}
EOM

다음 단계