ocket8888 commented on a change in pull request #5544: URL: https://github.com/apache/trafficcontrol/pull/5544#discussion_r583780911
########## File path: traffic_ops/traffic_ops_golang/api/async_status.go ########## @@ -0,0 +1,136 @@ +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 ( + "database/sql" + "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` + +// GetAsyncStatus returns the status of an asynchronous job. +func GetAsyncStatus(w http.ResponseWriter, r *http.Request) { + inf, userErr, sysErr, errCode := NewInfo(r, []string{"id"}, nil) Review comment: I think `id` should be provided in the `IntParams` argument to ensure it's the proper type in `NewInfo` without any extra work on your part. ---------------------------------------------------------------- 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]
