शेड्यूल किए गए टास्क के लिए, डिलीवरी व्हीकल बनाएं

इस दस्तावेज़ में, सर्वर एनवायरमेंट से वाहन बनाने का तरीका बताया गया है. इसके लिए, या तो gRPC या REST. ड्राइवर SDK टूल से वाहन बनाया जा सकता है. हालांकि, इसके लिए ज़रूरी है कि आपने ऐप्लिकेशन को सुरक्षित बनाने के लिए, क्रेडेंशियल डालें.

वाहन बनाने के लिए, ड्राइवर SDK टूल का इस्तेमाल करने का तरीका जानने के लिए, यह लेख पढ़ें:

सर्वर एनवायरमेंट से नया वाहन बनाने के लिए, फ़्लीट इंजन को CreateDeliveryVehicle का अनुरोध. इसका इस्तेमाल करें नए एट्रिब्यूट के एट्रिब्यूट तय करने के लिए, CreateDeliveryVehicleRequest ऑब्जेक्ट डिलीवरी वाहन.

शेड्यूल किए गए टास्क वाले वाहनों के लिए फ़ील्ड

DeliveryVehicle बनाते समय, ये वैकल्पिक फ़ील्ड सेट किए जाते हैं:

  • attributes
  • last_location
  • type

कोई वैकल्पिक फ़ील्ड सेट किए बिना वाहन बनाने के लिए, CreateDeliveryVehicleRequest में DeliveryVehicle फ़ील्ड को अनसेट किया गया.

वाहन के उदाहरण बनाएं

कोई वाहन या REST बनाने के लिए, Java gRPC लाइब्रेरी का इस्तेमाल किया जा सकता है.

Java

  static final String PROJECT_ID = "my-delivery-co-gcp-project";
  static final String VEHICLE_ID = "vehicle-8241890"; // Avoid auto-incrementing IDs.

  DeliveryServiceBlockingStub deliveryService =
    DeliveryServiceGrpc.newBlockingStub(channel);

  // Vehicle settings
  String parent = "providers/" + PROJECT_ID;
  DeliveryVehicle vehicle = DeliveryVehicle.newBuilder()
    .addAttributes(DeliveryVehicleAttribute.newBuilder()
      .setKey("route_number").setValue("1"))  // Opaque to the Fleet Engine
    .build();

  // Vehicle request
  CreateDeliveryVehicleRequest createVehicleRequest =
    CreateDeliveryVehicleRequest.newBuilder()  // No need for the header
        .setParent(parent)
        .setDeliveryVehicleId(VEHICLE_ID)     // Vehicle ID assigned by the Provider
        .setDeliveryVehicle(vehicle)
        .build();

  // Error handling
  // If Fleet Engine does not have vehicle with that ID and the credentials of the
  // requestor pass, the service creates the vehicle successfully.

  try {
    DeliveryVehicle createdVehicle =
      deliveryService.createDeliveryVehicle(createVehicleRequest);
  } catch (StatusRuntimeException e) {
    Status s = e.getStatus();
    switch (s.getCode()) {
       case ALREADY_EXISTS:
         break;
       case PERMISSION_DENIED:
         break;
    }
    return;
  }

आराम

सर्वर एनवायरमेंट से वाहन बनाने के लिए, एचटीटीपी REST कॉल करें CreateDeliveryVehicle को:

POST https://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles?deliveryVehicleId=<id>

पीओएसटी का मुख्य हिस्सा, बनाई जाने वाली DeliveryVehicle इकाई की जानकारी देता है. आप निम्न वैकल्पिक फ़ील्ड दर्ज करें:

  • attributes
  • lastLocation
  • type
  # Set $JWT, $PROJECT_ID, and $VEHICLE_ID in the local
  # environment
  curl -X POST "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles?deliveryVehicleId=${VEHICLE_ID}" \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer ${JWT}" \
  --data-binary @- << EOM
  {
    "attributes": [{"key": "model", "value": "sedan"}],
    "lastLocation": {"location": {"latitude": 12.1, "longitude": 14.5}}
  }
  EOM

फ़ील्ड सेट किए बिना वाहन बनाने के लिए, पीओएसटी का मुख्य हिस्सा छोड़ दें अनुरोध खाली है. यह नया वाहन, वाहन का आईडी एक्सट्रैक्ट करता है: पोस्ट यूआरएल में deliveryVehicleId पैरामीटर.

उदाहरण:

  # Set $JWT, $PROJECT_ID, and $VEHICLE_ID in the local
  # environment
  curl -X POST "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles?deliveryVehicleId=${VEHICLE_ID}" \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer ${JWT}"

आगे क्या करना है