Skip to content

Commit

Permalink
Use task request labels to encode information required by dashboard (#…
Browse files Browse the repository at this point in the history
…912)

* Custom task type support, refactor tasks to be singular, cleaned up

Signed-off-by: Aaron Chong <[email protected]>

* lint

Signed-off-by: Aaron Chong <[email protected]>

* Make custom task always available

Signed-off-by: Aaron Chong <[email protected]>

* Check exception for TypeError

Signed-off-by: Aaron Chong <[email protected]>

* Unifying handleTaskDescriptionChange, added FIXME for allowing favoriting custom tasks

Signed-off-by: Aaron Chong <[email protected]>

* Renaming custom to custom_compose, since the task category will always be compose, display description for short description

Signed-off-by: Aaron Chong <[email protected]>

* Catch possible exception with JSON.stringify, add fixmes for task description assumptions

Signed-off-by: Aaron Chong <[email protected]>

* Pickup and destination in task state labels

Signed-off-by: Aaron Chong <[email protected]>

* Clean up past workaround where pickup and destination is saved when a request is saved

Signed-off-by: Aaron Chong <[email protected]>

* Migration script

Signed-off-by: Aaron Chong <[email protected]>

* Remove stale testing label, push label instead of setting

Signed-off-by: Aaron Chong <[email protected]>

* Lint

Signed-off-by: Aaron Chong <[email protected]>

* Hammer/use labels schedules (#921)

* Getting ScheduledTask as well

Signed-off-by: Aaron Chong <[email protected]>

* Handle schedules as well

Signed-off-by: Aaron Chong <[email protected]>

* lint

Signed-off-by: Aaron Chong <[email protected]>

---------

Signed-off-by: Aaron Chong <[email protected]>

* Using a new generated file to handle parsing between json and object

Signed-off-by: Aaron Chong <[email protected]>

* Made fields all optional, nested in a description object, regenerated api-client

Signed-off-by: Aaron Chong <[email protected]>

* Using Ajv properly, with basic json stringify and parse

Signed-off-by: Aaron Chong <[email protected]>

* Renaming to task booking label, with the endpoint getting the label from the state, instead of the request

Signed-off-by: Aaron Chong <[email protected]>

* Generated API client after rename

Signed-off-by: Aaron Chong <[email protected]>

* Changes to dashboard and react components after rename

Signed-off-by: Aaron Chong <[email protected]>

* Refactoring and moving ajx instance to react-components

Signed-off-by: Aaron Chong <[email protected]>

* Updated migration scipt to use TaskBookingLabel and task_name

Signed-off-by: Aaron Chong <[email protected]>

* Handles editing scheduled task

Signed-off-by: Aaron Chong <[email protected]>

* clean up task favorite models

Signed-off-by: Aaron Chong <[email protected]>

* Adding label to favorite task before saving, setting booking label state when fav task is clicked

Signed-off-by: Aaron Chong <[email protected]>

* Lint

Signed-off-by: Aaron Chong <[email protected]>

* Added notes about TaskFavorite in migration script

Signed-off-by: Aaron Chong <[email protected]>

* Description of TaskBookingLabel

Signed-off-by: Aaron Chong <[email protected]>

* Fix migration script

Signed-off-by: Aaron Chong <[email protected]>

* task_definition_id for TaskFavorite

Signed-off-by: Aaron Chong <[email protected]>

* Use mandatory task_definition_id instead of task_name

Signed-off-by: Aaron Chong <[email protected]>

* Generate label only before dispatching

Signed-off-by: Aaron Chong <[email protected]>

* Clean up of emergency lots usage in config

Signed-off-by: Aaron Chong <[email protected]>

* Removed unused map

Signed-off-by: Aaron Chong <[email protected]>

* Lint

Signed-off-by: Aaron Chong <[email protected]>

* New generic TaskLabel tortoise model, to handle more custom label fields for sorting and filtering

Signed-off-by: Aaron Chong <[email protected]>

* Fix migration script

Signed-off-by: Aaron Chong <[email protected]>

* Added float field, and more comments on the steps of label creation and saving

Signed-off-by: Aaron Chong <[email protected]>

---------

Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth authored May 23, 2024
1 parent 9136efd commit 38d5869
Show file tree
Hide file tree
Showing 30 changed files with 995 additions and 428 deletions.
261 changes: 174 additions & 87 deletions packages/api-client/lib/openapi/api.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/api-client/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models';

export const version = {
rmfModels: rmfModelVer,
rmfServer: 'fd45675f94b75df6845303db4f45276d0998f3e6',
rmfServer: '98741b14ceca74208ca98e4bb0c3ca9e41ca1e3c',
openapiGenerator: '6.2.1',
};
98 changes: 66 additions & 32 deletions packages/api-client/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,36 @@ export default {
},
},
},
'/tasks/{task_id}/booking_label': {
get: {
tags: ['Tasks'],
summary: 'Get Task Booking Label',
operationId: 'get_task_booking_label_tasks__task_id__booking_label_get',
parameters: [
{
description: 'task_id',
required: true,
schema: { title: 'Task Id', type: 'string', description: 'task_id' },
name: 'task_id',
in: 'path',
},
],
responses: {
'200': {
description: 'Successful Response',
content: {
'application/json': { schema: { $ref: '#/components/schemas/TaskBookingLabel' } },
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
},
'/tasks/{task_id}/log': {
get: {
tags: ['Tasks'],
Expand Down Expand Up @@ -1556,7 +1586,7 @@ export default {
schema: {
title: 'Response Get Favorites Tasks Favorite Tasks Get',
type: 'array',
items: { $ref: '#/components/schemas/TaskFavoritePydantic' },
items: { $ref: '#/components/schemas/TaskFavorite' },
},
},
},
Expand All @@ -1569,20 +1599,14 @@ export default {
operationId: 'post_favorite_task_favorite_tasks_post',
requestBody: {
content: {
'application/json': { schema: { $ref: '#/components/schemas/TaskFavoritePydantic' } },
'application/json': { schema: { $ref: '#/components/schemas/TaskFavorite' } },
},
required: true,
},
responses: {
'200': {
description: 'Successful Response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/api_server.models.tortoise_models.tasks.TaskFavorite.leaf',
},
},
},
content: { 'application/json': { schema: {} } },
},
'422': {
description: 'Validation Error',
Expand Down Expand Up @@ -3647,6 +3671,28 @@ export default {
},
},
},
TaskBookingLabel: {
title: 'TaskBookingLabel',
required: ['description'],
type: 'object',
properties: { description: { $ref: '#/components/schemas/TaskBookingLabelDescription' } },
description:
'This label is to be populated by any frontend during a task dispatch, by\nbeing added to TaskRequest.labels, which in turn populates\nTaskState.booking.labels, and can be used to display relevant information\nneeded for any frontends.',
},
TaskBookingLabelDescription: {
title: 'TaskBookingLabelDescription',
required: ['task_definition_id'],
type: 'object',
properties: {
task_definition_id: { title: 'Task Definition Id', type: 'string' },
unix_millis_warn_time: { title: 'Unix Millis Warn Time', type: 'integer' },
pickup: { title: 'Pickup', type: 'string' },
destination: { title: 'Destination', type: 'string' },
cart_id: { title: 'Cart Id', type: 'string' },
},
description:
'This description holds several fields that could be useful for frontend\ndashboards when dispatching a task, to then be identified or rendered\naccordingly back on the same frontend.',
},
TaskCancelResponse: {
title: 'TaskCancelResponse',
allOf: [{ $ref: '#/components/schemas/SimpleResponse' }],
Expand Down Expand Up @@ -3730,9 +3776,16 @@ export default {
},
additionalProperties: false,
},
TaskFavoritePydantic: {
title: 'TaskFavoritePydantic',
required: ['id', 'name', 'unix_millis_earliest_start_time', 'category', 'user'],
TaskFavorite: {
title: 'TaskFavorite',
required: [
'id',
'name',
'unix_millis_earliest_start_time',
'category',
'user',
'task_definition_id',
],
type: 'object',
properties: {
id: { title: 'Id', type: 'string' },
Expand All @@ -3745,6 +3798,7 @@ export default {
category: { title: 'Category', type: 'string' },
description: { title: 'Description', type: 'object' },
user: { title: 'User', type: 'string' },
task_definition_id: { title: 'Task Definition Id', type: 'string' },
},
},
TaskInterruptionRequest: {
Expand Down Expand Up @@ -4259,26 +4313,6 @@ export default {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTask',
},
},
'api_server.models.tortoise_models.tasks.TaskFavorite.leaf': {
title: 'TaskFavorite',
required: ['id', 'name', 'category', 'user'],
type: 'object',
properties: {
id: { title: 'Id', maxLength: 255, type: 'string' },
name: { title: 'Name', maxLength: 255, type: 'string' },
unix_millis_earliest_start_time: {
title: 'Unix Millis Earliest Start Time',
type: 'string',
format: 'date-time',
nullable: true,
},
priority: { title: 'Priority' },
category: { title: 'Category', maxLength: 255, type: 'string' },
description: { title: 'Description' },
user: { title: 'User', maxLength: 255, type: 'string' },
},
additionalProperties: false,
},
api_server__models__delivery_alerts__DeliveryAlert__Category: {
title: 'Category',
enum: ['missing', 'wrong', 'obstructed', 'cancelled'],
Expand Down
2 changes: 2 additions & 0 deletions packages/api-server/api_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
from .rmf_api.task_state_update import TaskStateUpdate
from .rmf_api.undo_skip_phase_request import UndoPhaseSkipRequest
from .rmf_api.undo_skip_phase_response import UndoPhaseSkipResponse
from .task_booking_label import *
from .task_favorite import *
from .user import *
46 changes: 46 additions & 0 deletions packages/api-server/api_server/models/task_booking_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from typing import Optional

import pydantic
from pydantic import BaseModel

# NOTE: This label model needs to exactly match the fields that are defined and
# populated by the dashboard. Any changes to either side will require syncing.


class TaskBookingLabelDescription(BaseModel):
"""
This description holds several fields that could be useful for frontend
dashboards when dispatching a task, to then be identified or rendered
accordingly back on the same frontend.
"""

task_definition_id: str
unix_millis_warn_time: Optional[int]
pickup: Optional[str]
destination: Optional[str]
cart_id: Optional[str]

@staticmethod
def from_json_string(json_str: str) -> Optional["TaskBookingLabelDescription"]:
try:
return TaskBookingLabelDescription.parse_raw(json_str)
except pydantic.error_wrappers.ValidationError:
return None


class TaskBookingLabel(BaseModel):
"""
This label is to be populated by any frontend during a task dispatch, by
being added to TaskRequest.labels, which in turn populates
TaskState.booking.labels, and can be used to display relevant information
needed for any frontends.
"""

description: TaskBookingLabelDescription

@staticmethod
def from_json_string(json_str: str) -> Optional["TaskBookingLabel"]:
try:
return TaskBookingLabel.parse_raw(json_str)
except pydantic.error_wrappers.ValidationError:
return None
14 changes: 14 additions & 0 deletions packages/api-server/api_server/models/task_favorite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Dict

from pydantic import BaseModel


class TaskFavorite(BaseModel):
id: str
name: str
unix_millis_earliest_start_time: int
priority: Dict | None
category: str
description: Dict | None
user: str
task_definition_id: str
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
TaskEventLogPhasesEventsLog,
TaskEventLogPhasesLog,
TaskFavorite,
TaskFavoritePydantic,
TaskLabel,
TaskRequest,
TaskState,
)
Expand Down
16 changes: 12 additions & 4 deletions packages/api-server/api_server/models/tortoise_models/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from tortoise.contrib.pydantic.creator import pydantic_model_creator
from tortoise.fields import (
BigIntField,
CharField,
DatetimeField,
FloatField,
ForeignKeyField,
ForeignKeyRelation,
JSONField,
Expand Down Expand Up @@ -30,6 +31,15 @@ class TaskState(Model):
unix_millis_warn_time = DatetimeField(null=True, index=True)
pickup = CharField(255, null=True, index=True)
destination = CharField(255, null=True, index=True)
labels = ReverseRelation["TaskLabel"]


class TaskLabel(Model):
state = ForeignKeyField("models.TaskState", null=True, related_name="labels")
label_name = CharField(255, null=False, index=True)
label_value_str = CharField(255, null=True, index=True)
label_value_num = BigIntField(null=True, index=True)
label_value_float = FloatField(null=True, index=True)


class TaskEventLog(Model):
Expand Down Expand Up @@ -80,6 +90,4 @@ class TaskFavorite(Model):
category = CharField(255, null=False, index=True)
description = JSONField()
user = CharField(255, null=False, index=True)


TaskFavoritePydantic = pydantic_model_creator(TaskFavorite)
task_definition_id = CharField(255, null=True, index=True)
Loading

0 comments on commit 38d5869

Please sign in to comment.