ocket8888 commented on a change in pull request #5544: URL: https://github.com/apache/trafficcontrol/pull/5544#discussion_r582285444
########## File path: traffic_ops/traffic_ops_golang/api/async_status.go ########## @@ -0,0 +1,104 @@ +package api + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import ( + "errors" + "net/http" + "time" + + "github.com/jmoiron/sqlx" +) + +const ( + AsyncSucceeded = "SUCCEEDED" + AsyncFailed = "FAILED" + AsyncPending = "PENDING" +) + +const CurrentAsyncEndpoint = "/api/4.0/async_status/" + +type AsyncStatus struct { + Id int `json:"id, omitempty" db:"id"` + Status string `json:"status, omitempty" db:"status"` + StartTime time.Time `json:"start_time, omitempty" db:"start_time"` + EndTime *time.Time `json:"end_time, omitempty" db:"end_time"` + Message *string `json:"message, omitempty" db:"message"` +} + +const SelectAsyncStatusQuery = `SELECT id, status, message, start_time, end_time from async_status WHERE id = $1` +const InsertAsyncStatusQuery = `INSERT INTO async_status (status, message) VALUES ($1, $2) RETURNING id` +const UpdateAsyncStatusEndTimeQuery = `UPDATE async_status SET status = $1, message = $2, end_time = now() WHERE id = $3` +const UpdateAsyncStatusQuery = `UPDATE async_status SET status = $1, message = $2 WHERE id = $3` Review comment: Can you add GoDoc comments to the exported symbols? Or not export them if they don't need to be exported. ########## File path: docs/source/api/v4/async_status.rst ########## @@ -0,0 +1,52 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-async_status: + +**************** +``async_status`` +**************** + +``GET`` +======= +Returns a status update for an asynchronous task. + +:Auth. Required: Yes +:Roles Required: "admin" or "operations" +:Response Type: Object + +Request Structure +----------------- +No parameters available + + +Response Structure +------------------ + Review comment: Missing response structure explanation. ########## File path: docs/source/api/v4/async_status.rst ########## @@ -0,0 +1,52 @@ +.. +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +.. See the License for the specific language governing permissions and +.. limitations under the License. +.. + +.. _to-api-async_status: + +**************** +``async_status`` +**************** + +``GET`` +======= +Returns a status update for an asynchronous task. + +:Auth. Required: Yes +:Roles Required: "admin" or "operations" +:Response Type: Object + +Request Structure +----------------- +No parameters available + + +Response Structure +------------------ + +.. code-block:: http + :caption: Response Example + + HTTP/1.1 200 OK + Content-Type: application/json + + { "response": + { + "id":1, + "status":"PENDING", + "start_time":"2021-02-18T17:13:56.352261Z", + "end_time":null, + "message":"Async job has started." + } + } Review comment: How do I know which job is mine, based on this? Since you're exposing these database IDs through the API anyway, maybe you could add a query or path parameter so that the returned Location/Alert can be `async_status/{{ID}}` or `async_status?id={{ID}}`? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
