Skip to content

Commit

Permalink
Query just the information needed for the table and nothing more
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Jan 24, 2024
1 parent 3641034 commit 2ec4494
Show file tree
Hide file tree
Showing 9 changed files with 873 additions and 32 deletions.
432 changes: 432 additions & 0 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: '4f6e8567a0a3a44896f60898e84130c2be8a94c7',
rmfServer: '3641034b187d5457610280b42b05663b25444104',
openapiGenerator: '6.2.1',
};
252 changes: 252 additions & 0 deletions packages/api-client/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,226 @@ export default {
},
},
},
'/tasks/queue_entry': {
get: {
tags: ['Tasks'],
summary: 'Query Task Queue Entry',
operationId: 'query_task_queue_entry_tasks_queue_entry_get',
parameters: [
{
description: 'comma separated list of task ids',
required: false,
schema: {
title: 'Task Id',
type: 'string',
description: 'comma separated list of task ids',
},
name: 'task_id',
in: 'query',
},
{
description: 'comma separated list of task categories',
required: false,
schema: {
title: 'Category',
type: 'string',
description: 'comma separated list of task categories',
},
name: 'category',
in: 'query',
},
{
description: 'comma separated list of requester names',
required: false,
schema: {
title: 'Requester',
type: 'string',
description: 'comma separated list of requester names',
},
name: 'requester',
in: 'query',
},
{
description: 'comma separated list of pickup names',
required: false,
schema: {
title: 'Pickup',
type: 'string',
description: 'comma separated list of pickup names',
},
name: 'pickup',
in: 'query',
},
{
description: 'comma separated list of destination names',
required: false,
schema: {
title: 'Destination',
type: 'string',
description: 'comma separated list of destination names',
},
name: 'destination',
in: 'query',
},
{
description: 'comma separated list of assigned robot names',
required: false,
schema: {
title: 'Assigned To',
type: 'string',
description: 'comma separated list of assigned robot names',
},
name: 'assigned_to',
in: 'query',
},
{
description: 'comma separated list of statuses',
required: false,
schema: {
title: 'Status',
type: 'string',
description: 'comma separated list of statuses',
},
name: 'status',
in: 'query',
},
{
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
required: false,
schema: {
title: 'Request Time Between',
type: 'string',
description:
'\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
},
name: 'request_time_between',
in: 'query',
},
{
description:
'\n The period of starting time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
required: false,
schema: {
title: 'Start Time Between',
type: 'string',
description:
'\n The period of starting time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ',
},
name: 'start_time_between',
in: 'query',
},
{
description:
'\n The period of finishing time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ',
required: false,
schema: {
title: 'Finish Time Between',
type: 'string',
description:
'\n The period of finishing time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ',
},
name: 'finish_time_between',
in: 'query',
},
{
description: 'defaults to 100',
required: false,
schema: {
title: 'Limit',
maximum: 1000.0,
exclusiveMinimum: 0.0,
type: 'integer',
description: 'defaults to 100',
},
name: 'limit',
in: 'query',
},
{
description: 'defaults to 0',
required: false,
schema: {
title: 'Offset',
minimum: 0.0,
type: 'integer',
description: 'defaults to 0',
},
name: 'offset',
in: 'query',
},
{
description:
"common separated list of fields to order by, prefix with '-' to sort descendingly.",
required: false,
schema: {
title: 'Order By',
type: 'string',
description:
"common separated list of fields to order by, prefix with '-' to sort descendingly.",
},
name: 'order_by',
in: 'query',
},
],
responses: {
'200': {
description: 'Successful Response',
content: {
'application/json': {
schema: {
title: 'Response Query Task Queue Entry Tasks Queue Entry Get',
type: 'array',
items: {
$ref: '#/components/schemas/api_server.models.tortoise_models.tasks.TaskState.leaf',
},
},
},
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
},
'/tasks/{task_id}/queue_entry': {
get: {
tags: ['Tasks'],
summary: 'Get Task Queue Entry',
description: 'Available in socket.io',
operationId: 'get_task_queue_entry_tasks__task_id__queue_entry_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/api_server.models.tortoise_models.tasks.TaskState.leaf',
},
},
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
},
'/tasks/{task_id}/log': {
get: {
tags: ['Tasks'],
Expand Down Expand Up @@ -4194,6 +4414,38 @@ export default {
},
additionalProperties: false,
},
'api_server.models.tortoise_models.tasks.TaskState.leaf': {
title: 'TaskState',
required: ['id_'],
type: 'object',
properties: {
id_: { title: 'Id ', maxLength: 255, type: 'string' },
assigned_to: { title: 'Assigned To', maxLength: 255, type: 'string', nullable: true },
unix_millis_start_time: {
title: 'Unix Millis Start Time',
type: 'string',
format: 'date-time',
nullable: true,
},
unix_millis_finish_time: {
title: 'Unix Millis Finish Time',
type: 'string',
format: 'date-time',
nullable: true,
},
status: { title: 'Status', maxLength: 255, type: 'string', nullable: true },
unix_millis_request_time: {
title: 'Unix Millis Request Time',
type: 'string',
format: 'date-time',
nullable: true,
},
requester: { title: 'Requester', maxLength: 255, type: 'string', nullable: true },
pickup: { title: 'Pickup', maxLength: 255, type: 'string', nullable: true },
destination: { title: 'Destination', maxLength: 255, type: 'string', nullable: true },
},
additionalProperties: false,
},
api_server__models__rmf_api__fleet_log__FleetState: {
title: 'FleetState',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
TaskEventLogPhasesLog,
TaskFavorite,
TaskFavoritePydantic,
TaskQueueEntryPydantic,
TaskRequest,
TaskState,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ class TaskFavorite(Model):
user = CharField(255, null=False, index=True)


TaskQueueEntryPydantic = pydantic_model_creator(
TaskState, exclude=("data", "category", "unix_millis_warn_time")
)
TaskFavoritePydantic = pydantic_model_creator(TaskFavorite)
54 changes: 54 additions & 0 deletions packages/api-server/api_server/repositories/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
LogEntry,
Pagination,
Phases,
Status,
TaskEventLog,
TaskRequest,
TaskState,
Expand All @@ -22,6 +23,7 @@
from api_server.models import tortoise_models as ttm
from api_server.models.rmf_api.log_entry import Tier
from api_server.models.rmf_api.task_state import Category, Id, Phase
from api_server.models.tortoise_models import TaskQueueEntryPydantic
from api_server.models.tortoise_models import TaskRequest as DbTaskRequest
from api_server.models.tortoise_models import TaskState as DbTaskState
from api_server.query import add_pagination
Expand Down Expand Up @@ -242,6 +244,58 @@ async def get_task_state(self, task_id: str) -> Optional[TaskState]:
return None
return TaskState(**result.data)

async def query_task_queue_entry(
self, query: QuerySet[DbTaskState], pagination: Optional[Pagination] = None
) -> List[TaskQueueEntryPydantic]:
try:
if pagination:
query = add_pagination(query, pagination)
# TODO: enforce with authz
results = await query.values(
"id_",
"assigned_to",
"unix_millis_start_time",
"unix_millis_finish_time",
"status",
"unix_millis_request_time",
"requester",
"pickup",
"destination",
)
entries = []
for r in results:
print(r["assigned_to"])
status = r["status"]
if "Status." in status:
r["status"] = r["status"].split("Status.")[1]
entries.append(TaskQueueEntryPydantic(**r))
return entries
except FieldError as e:
raise HTTPException(422, str(e)) from e

async def get_task_queue_entry(
self, task_id: str
) -> Optional[TaskQueueEntryPydantic]:
# TODO: enforce with authz
result = await DbTaskState.get_or_none(id_=task_id).values(
"id_",
"assigned_to",
"unix_millis_start_time",
"unix_millis_finish_time",
"status",
"unix_millis_request_time",
"requester",
"pickup",
"destination",
)
if result is None:
return None

status = result["status"]
if status is not None and "Status." in status:
result["status"] = result["status"].split("Status.")[1]
return TaskQueueEntryPydantic(**result)

async def get_task_log(
self, task_id: str, between: Tuple[int, int]
) -> Optional[TaskEventLog]:
Expand Down
Loading

0 comments on commit 2ec4494

Please sign in to comment.