Görevleri toplu olarak oluşturma

Bu belgede, sunucu ortamından nasıl görev grubu oluşturulacağı açıklanmaktadır. ya da REST kullanarak yapabilirsiniz. Görev oluşturma hakkında daha fazla bilgi için aşağıdaki konulara göz atın:

Görevleri toplu olarak oluşturmak için görev alanları

Toplu olarak görev oluştururken requests içindeki her CreateTasksRequest öğesi tek bir görev için CreateTask isteğiyle aynı doğrulama kurallarını geçmelidir. ancak parent ve header alanlarının isteğe bağlı olması gerekir. Ayarlanırsa üst düzeydeki ilgili alanlarıyla aynı olmalıdırlar. BatchCreateTasksRequest

Daha fazla bilgi için BatchCreateTasks API Referansı belgelerine bakın gRPC veya REST için.

Zorunlu grup alanları

AlanDeğer
istek Array<CreateTasksRequest>

İsteğe bağlı toplu görev alanları

AlanDeğer
başlık DeliveryRequestHeader

Bir görev grubu oluşturma

Aşağıdaki örneklerde hem teslim alma hem de teslimat görevlerinin nasıl oluşturulacağı gösterilmektedir veya Java gRPC kitaplığını kullanarak ya da 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

Sunucu ortamından teslim ve teslim alma görevi oluşturmak için BatchCreateTasks için HTTP REST çağrısı:

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

&lt;id&gt;, görev için benzersiz bir tanımlayıcıdır.

İstek başlığında şu değeri içeren Authorization (Yetkilendirme) alanı bulunmalıdır: Taşıyıcı <token>, burada <token> sunucunuz tarafından verilir. Hizmet hesabı rolleri ve JSON Web jetonları.

İstek gövdesinde bir BatchCreateTasksRequest varlığı bulunmalıdır.

Örnek curl komutu:

# 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

Sırada ne var?