Menyelesaikan tugas
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dokumen ini mengasumsikan bahwa Anda memahami cara membuat dan menggunakan tugas. Berikut contoh spesifik cara menyelesaikan tugas pengiriman:
Menutup tugas: Menutup tugas pengiriman akan mengubah statusnya menjadi CLOSED
dan
menunjukkan bahwa tugas tersebut tidak lagi aktif.
Tetapkan hasil tugas: Setelah tugas ditutup, Anda kemudian menyelesaikannya dengan
menetapkan hasilnya ke SUCCEEDED
atau FAILED
. Ini adalah bagian penting dalam menyelesaikan tugas untuk menampilkan hasil pengiriman dalam berbagi perjalanan dan memastikan penagihan yang benar untuk layanan Fleet Engine.
Menutup tugas
Anda dapat menutup tugas dengan cara berikut:
- Perbarui status penghentian untuk kendaraan. Anda menghapus perhentian dari
kendaraan, yang pada gilirannya menutup semua tugas yang terkait dengan perhentian. Lihat
Memperbarui status perhentian untuk mengetahui detailnya.
- Hapus tugas dari daftar perhentian kendaraan. Hal ini melibatkan pembaruan
daftar tugas untuk perhentian, tetapi dengan tugas yang ditutup tidak
lagi menjadi bagian dari daftar. Lihat Memperbarui urutan tugas di Memperbarui tugas.
- Tetapkan status tugas ke
CLOSED
. Tindakan ini hanya dapat dilakukan pada tugas yang tidak
ditetapkan ke kendaraan. Bagian ini menunjukkan pendekatan ini.
Setelah menutup tugas, Anda tidak dapat membukanya kembali.
Penutupan tugas tidak menunjukkan keberhasilan atau kegagalannya. Hal ini menunjukkan bahwa tugas tidak lagi dianggap sedang dalam proses. Untuk menunjukkan hasil sebenarnya dari suatu tugas dan menampilkannya untuk tujuan Pelacakan Armada dan berbagi perjalanan, Anda harus menunjukkan hasil sebenarnya dari suatu tugas. Lihat
Menetapkan hasil tugas di bawah.
Kolom tugas untuk menutup tugas
Bagian ini mendokumentasikan kolom yang diperlukan untuk ditetapkan saat menutup
tugas. Fleet Engine mengabaikan semua kolom lain dalam entity untuk update.
Kolom wajib diisi |
Nilai |
state |
State.CLOSED |
Menutup tugas secara langsung
Contoh berikut menunjukkan cara menyetel tugas yang tidak ditetapkan ke status tertutup,
baik di gRPC maupun menggunakan panggilan permintaan HTTP REST ke UpdateTask
gRPC
static final String PROJECT_ID = "my-delivery-co-gcp-project";
static final String TASK_ID = "task-8241890";
DeliveryServiceBlockingStub deliveryService =
DeliveryServiceGrpc.newBlockingStub(channel);
// Task settings
String taskName = "providers/" + PROJECT_ID + "/tasks/" + TASK_ID;
Task task = Task.newBuilder()
.setName(taskName)
.setState(Task.State.CLOSED) // You can only directly CLOSE a
.build(); // task that is NOT assigned to a vehicle.
// Task request
UpdateTaskRequest updateTaskRequest =
UpdateTaskRequest.newBuilder() // No need for the header
.setTask(task)
.setUpdateMask(FieldMask.newBuilder().addPaths("state"))
.build();
try {
Task updatedTask = deliveryService.updateTask(updateTaskRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case NOT_FOUND:
break;
case PERMISSION_DENIED:
break;
}
return;
}
REST
PATCH https://fleetengine.googleapis.com/v1/providers/<project_id>/tasks/<id>?updateMask=state
- <id> adalah ID unik untuk tugas.
- Header permintaan harus berisi kolom Authorization dengan nilai
Bearer <token>, dengan <token> dikeluarkan oleh server Anda
sesuai dengan panduan yang dijelaskan dalam Peran akun layanan dan
Token Web JSON.
- Anda harus menyertakan entitas
Task
dalam isi permintaan
Contoh perintah curl
:
# Set JWT, PROJECT_ID, and TASK_ID in the local environment
curl -X PATCH "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=state,taskOutcome,taskOutcomeTime" \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${JWT}" \
--data-binary @- << EOM
{
"state": "CLOSED",
"taskOutcome": "SUCCEEDED",
"taskOutcomeTime": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
EOM
Menetapkan hasil tugas
Untuk menunjukkan hasil sebenarnya dari suatu tugas, Anda menetapkan hasil untuk tugas yang ditutup ke SUCCEEDED
atau FAILED
. Tugas harus ditutup sebelum Anda menetapkan hasilnya. Fleet Engine hanya menagih tugas pengiriman dengan status
SUCCEEDED
.
Detail hasil tugas
Tugas juga memberikan detail tambahan tentang hasil tugas. Anda dapat menyetelnya
secara langsung dan Fleet Engine akan mematuhi setelan Anda:
- Lokasi hasil tugas: Fleet Engine otomatis mengisi lokasi hasil tugas dengan lokasi terakhir yang diketahui dari kendaraan. Anda dapat memberikan ini
sebagai gantinya jika mau.
- Waktu hasil tugas: Fleet Engine tidak mengisi kolom ini, tetapi tersedia untuk Anda tetapkan.
Anda dapat menggunakan salah satu pendekatan berikut untuk menetapkan task_outcome_location
dan task_outcome_time
:
- Perbarui dalam permintaan yang sama yang menetapkan hasil tugas.
- Perbarui nanti, setelah Anda menetapkan hasil tugas.
- Mengubahnya lagi setelah ditetapkan.
Fleet Engine mencegah pembaruan berikut yang terkait dengan hasil tugas:
- Anda tidak dapat mengubah hasil tugas setelah ditetapkan ke
SUCCEEDED
atau
FAILED
.
- Anda tidak dapat menyetel lokasi hasil tugas atau waktu hasil untuk tugas tanpa
hasil yang ditetapkan.
Kolom tugas untuk menetapkan hasil
Bagian ini mendokumentasikan kolom wajib dan opsional yang harus ditetapkan saat menyetel hasil tugas. Fleet Engine mengabaikan kolom lain dalam entitas untuk pembaruan.
Kolom wajib diisi |
Nilai |
taskOutcome |
Outcome.SUCCEEDED atau Outcome.FAILED |
Kolom opsional | Nilai |
taskOutcomeLocation |
Lokasi tempat tugas diselesaikan. Jika tidak disetel, Fleet Engine
akan menetapkan nilai ini secara default ke lokasi kendaraan terakhir. |
taskOutcomeTime |
Stempel waktu saat tugas diselesaikan. |
Contoh hasil tugas
Contoh berikut menunjukkan cara menggunakan library gRPC Java dan panggilan REST HTTP ke UpdateTask
untuk menetapkan hasil tugas ke SUCCEEDED
dan menetapkan lokasi tempat tugas diselesaikan.
gRPC
static final String PROJECT_ID = "my-delivery-co-gcp-project";
static final String TASK_ID = "task-8241890";
DeliveryServiceBlockingStub deliveryService =
DeliveryServiceGrpc.newBlockingStub(channel);
// Task settings
String taskName = "providers/" + PROJECT_ID + "/tasks/" + TASK_ID;
Task task = Task.newBuilder()
.setName(taskName)
.setTaskOutcome(TaskOutcome.SUCCEEDED)
.setTaskOutcomeTime(now())
.setTaskOutcomeLocation( // Grand Indonesia East Mall
LocationInfo.newBuilder().setPoint(
LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))
.build();
// Task request
UpdateTaskRequest updateTaskRequest =
UpdateTaskRequest.newBuilder() // No need for the header
.setTask(task)
.setUpdateMask(FieldMask.newBuilder().addPaths("task_outcome", "task_outcome_time", "task_outcome_location"))
.build();
try {
Task updatedTask = deliveryService.updateTask(updateTaskRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case NOT_FOUND:
break;
case PERMISSION_DENIED:
break;
}
return;
}
REST
PATCH https://fleetengine.googleapis.com/v1/providers/<project_id>/tasks/<id>?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation
- <id> adalah ID unik untuk tugas.
- Header permintaan harus berisi kolom Authorization dengan nilai
Bearer <token>, dengan <token> dikeluarkan oleh server Anda
sesuai dengan panduan yang dijelaskan dalam Peran akun layanan dan
Token Web JSON.
- Isi permintaan harus berisi entitas
Task
.
# Set JWT, PROJECT_ID, and TASK_ID in the local environment
curl -X PATCH "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation" \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${JWT}" \
--data-binary @- << EOM
{
"taskOutcome": "SUCCEEDED",
"taskOutcomeTime": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"taskOutcomeLocation": {
"point": {
"latitude": -6.195139,
"longitude": 106.820826
}
}
}
EOM
Langkah berikutnya
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-08-16 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-16 UTC."],[[["\u003cp\u003eThis document explains how to finalize shipment tasks in Fleet Engine by closing them and setting their outcome to \u003ccode\u003eSUCCEEDED\u003c/code\u003e or \u003ccode\u003eFAILED\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eClosing a task indicates it is no longer in progress, while setting the outcome reflects the delivery result for billing and journey sharing.\u003c/p\u003e\n"],["\u003cp\u003eTasks can be closed by updating the vehicle's stop status, removing them from the vehicle's stop list, or setting their state to \u003ccode\u003eCLOSED\u003c/code\u003e if unassigned.\u003c/p\u003e\n"],["\u003cp\u003eThe task outcome, location, and time can be set using the \u003ccode\u003eUpdateTask\u003c/code\u003e method with appropriate fields and values, but the outcome cannot be changed once set.\u003c/p\u003e\n"]]],["To finalize shipment tasks, you must first close them, setting the `state` to `CLOSED`, which indicates the task is no longer active. Closing can be done by updating the vehicle's stop status, removing the task from the vehicle's stop list, or directly setting the task state. Once closed, set the `taskOutcome` to `SUCCEEDED` or `FAILED`, with optional details like `taskOutcomeLocation` and `taskOutcomeTime`. The task outcome is essential for journey sharing and billing. You can use gRPC or HTTP REST calls to accomplish both.\n"],null,["This document assumes you understand how to create and use tasks. It provides\nspecific examples for how to finalize shipment tasks as follows:\n\n- **Close a task** : Closing a shipment task changes its state to `CLOSED` and\n indicates that that task is no longer active.\n\n- **Set the task outcome** : Once a task is closed, you then finalize it by\n setting its outcome to either `SUCCEEDED` or `FAILED`. This is an important\n part of finalizing a task in order to show the delivery outcome in journey\n sharing and to ensure correct billing for the Fleet Engine service.\n\nClose a task\n\nYou can close a task in the following ways:\n\n- **Update the stop status for the vehicle** . You remove the stop from the vehicle, which in turn closes all tasks associated with the stop. See [Update stop status for details](/maps/documentation/mobility/fleet-engine/journeys/tasks/update-stops).\n- **Remove the task from the list of vehicle stops** . This involves updating the list of tasks for the stop, but with the closed task no longer part of the list. See Update task order in [Update tasks](/maps/documentation/mobility/fleet-engine/journeys/tasks/update-tasks).\n- **Set the task state to `CLOSED`**. This can only be done on tasks not assigned to vehicles. This section shows this approach.\n\nOnce you close a task, you may not reopen it.\n\u003e \u003e **Closing of a task does not indicate its success or failure** . It indicates\n\u003e \u003e that the task is no longer considered in progress. In order to indicate the\n\u003e \u003e actual outcome of a task and to have that displayed for Fleet Tracking and\n\u003e \u003e journey sharing purposes, you must indicate the actual outcome of a task. See\n\u003e \u003e [Set the task outcome](#set-task-outcome) below.\n\nTask fields for closing tasks\n\nThis section documents the required fields to set when closing a\ntask. Fleet engine ignores all other fields in the entity for the update.\n\n\u003cbr /\u003e\n\n| Required field | Value |\n|----------------|----------------|\n| `state` | `State.CLOSED` |\n\n\u003cbr /\u003e\n\nClose a task directly\n\nThe following examples show how to set an unassigned task to a closed state,\neither in gRPC or using an HTTP REST request call to `UpdateTask` \n\ngRPC \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String TASK_ID = \"task-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Task settings\n String taskName = \"providers/\" + PROJECT_ID + \"/tasks/\" + TASK_ID;\n Task task = Task.newBuilder()\n .setName(taskName)\n .setState(Task.State.CLOSED) // You can only directly CLOSE a\n .build(); // task that is NOT assigned to a vehicle.\n\n // Task request\n UpdateTaskRequest updateTaskRequest =\n UpdateTaskRequest.newBuilder() // No need for the header\n .setTask(task)\n .setUpdateMask(FieldMask.newBuilder().addPaths(\"state\"))\n .build();\n\n try {\n Task updatedTask = deliveryService.updateTask(updateTaskRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nREST\n\n`PATCH https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/tasks/\u003cid\u003e?updateMask=state`\n\n- *\\\u003cid\\\u003e* is a unique identifier for the task.\n- The request header must contain a field *Authorization* with the value *Bearer \\\u003ctoken\\\u003e* , where *\\\u003ctoken\\\u003e* is issued by your server according to the guidelines described in [Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts) and [JSON Web tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/jwt).\n- You must include a `Task` entity in the request body\n\nExample `curl` command: \n\n # Set JWT, PROJECT_ID, and TASK_ID in the local environment\n curl -X PATCH \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=state,taskOutcome,taskOutcomeTime\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"state\": \"CLOSED\",\n \"taskOutcome\": \"SUCCEEDED\",\n \"taskOutcomeTime\": \"$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")\"\n }\n EOM\n\nSet the task outcome\n\nTo indicate the actual outcome of a task, you set the outcome for closed tasks\nto either `SUCCEEDED` or `FAILED`. A task must be closed before you set its\noutcome. Fleet Engine only charges for delivery tasks with a state of\n`SUCCEEDED`.\n\nTask outcome details\n\nTasks also provide additional details about the task outcome. You can set these\ndirectly and Fleet Engine respects your settings:\n\n- **Task outcome location**: Fleet Engine automatically fills in the task outcome location with the last known vehicle location. You can provide this instead if you prefer.\n- **Task outcome time**: Fleet Engine does not fill this field in, but is available for you to set.\n\nYou can use any of the following approaches to setting `task_outcome_location`\nand `task_outcome_time`:\n\n- **Update them in the same request** that sets the task outcome.\n- **Update them later**, after you have set task outcome.\n- **Modify them again** after they have been set.\n\nFleet Engine prevents the following updates related to task outcomes:\n\n- **You can't modify a task outcome once it is set** to either `SUCCEEDED` or `FAILED`.\n- **You can't set a task outcome location or outcome time** for tasks without a set outcome.\n\nTask fields for setting outcome\n\nThis section documents the required and optional fields to set when setting a\ntask outcome. Fleet Engine ignores other fields in the entity for the update.\n\n\u003cbr /\u003e\n\n| Required field | Value |\n|----------------|-----------------------------------------|\n| `taskOutcome` | `Outcome.SUCCEEDED` or `Outcome.FAILED` |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Optional field | Value |\n|-----------------------|-----------------------------------------------------------------------------------------------------------------|\n| `taskOutcomeLocation` | The location where the task was completed. If not set, Fleet Engine defaults this to the last vehicle location. |\n| `taskOutcomeTime` | The timestamp when the task was completed. |\n\n\u003cbr /\u003e\n\nTask outcome examples\n\nThe following example shows how to use the [Java gRPC library](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-tasks) and an HTTP\nREST call to `UpdateTask` to set a task outcome to `SUCCEEDED` and set the\nlocation where the task was completed. \n\ngRPC \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String TASK_ID = \"task-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Task settings\n String taskName = \"providers/\" + PROJECT_ID + \"/tasks/\" + TASK_ID;\n Task task = Task.newBuilder()\n .setName(taskName)\n .setTaskOutcome(TaskOutcome.SUCCEEDED)\n .setTaskOutcomeTime(now())\n .setTaskOutcomeLocation( // Grand Indonesia East Mall\n LocationInfo.newBuilder().setPoint(\n LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))\n .build();\n\n // Task request\n UpdateTaskRequest updateTaskRequest =\n UpdateTaskRequest.newBuilder() // No need for the header\n .setTask(task)\n .setUpdateMask(FieldMask.newBuilder().addPaths(\"task_outcome\", \"task_outcome_time\", \"task_outcome_location\"))\n .build();\n\n try {\n Task updatedTask = deliveryService.updateTask(updateTaskRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nREST\n\n`PATCH https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/tasks/\u003cid\u003e?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation`\n\n- *\\\u003cid\\\u003e* is a unique identifier for the task.\n- The request header must contain a field *Authorization* with the value *Bearer \\\u003ctoken\\\u003e* , where *\\\u003ctoken\\\u003e* is issued by your server according to the guidelines described in [Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts) and [JSON Web tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/jwt).\n- The request body must contain a `Task` entity.\n\n # Set JWT, PROJECT_ID, and TASK_ID in the local environment\n curl -X PATCH \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"taskOutcome\": \"SUCCEEDED\",\n \"taskOutcomeTime\": \"$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")\",\n \"taskOutcomeLocation\": {\n \"point\": {\n \"latitude\": -6.195139,\n \"longitude\": 106.820826\n }\n }\n }\n EOM\n\nWhat's next\n\n- [Find tasks](/maps/documentation/mobility/fleet-engine/journeys/tasks/find-tasks)"]]