mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-19 02:14:35 +08:00
fix: raise timeout for trader lifecycle calls to survive slow stop/restart
Live click-through showed PUT /traders/:id taking 33.8s (stopping the running instance waits for its in-flight cycle and monitor goroutines) while the axios default timeout is 30s — the frontend aborted a request that succeeded server-side and reported a false launch failure. Create/update/start now use a 120s ceiling.
This commit is contained in:
@@ -6,6 +6,12 @@ import type {
|
|||||||
import { API_BASE, httpClient } from './helpers'
|
import { API_BASE, httpClient } from './helpers'
|
||||||
import { ApiError } from '../httpClient'
|
import { ApiError } from '../httpClient'
|
||||||
|
|
||||||
|
// Create/update/start legitimately run long: stopping a live trader waits for
|
||||||
|
// its in-flight cycle and monitors, and creation probes the exchange (~35s
|
||||||
|
// worst case observed). The default 30s axios timeout aborts mid-operation and
|
||||||
|
// reports a false failure, so these calls get their own generous ceiling.
|
||||||
|
const TRADER_LIFECYCLE_TIMEOUT_MS = 120_000
|
||||||
|
|
||||||
function throwApiError(
|
function throwApiError(
|
||||||
message: string,
|
message: string,
|
||||||
errorKey?: string,
|
errorKey?: string,
|
||||||
@@ -33,10 +39,11 @@ export const traderApi = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async createTrader(request: CreateTraderRequest): Promise<TraderInfo> {
|
async createTrader(request: CreateTraderRequest): Promise<TraderInfo> {
|
||||||
const result = await httpClient.post<TraderInfo>(
|
const result = await httpClient.request<TraderInfo>(`${API_BASE}/traders`, {
|
||||||
`${API_BASE}/traders`,
|
method: 'POST',
|
||||||
request
|
data: request,
|
||||||
)
|
timeout: TRADER_LIFECYCLE_TIMEOUT_MS,
|
||||||
|
})
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
throwApiError(
|
throwApiError(
|
||||||
result.message || 'Failed to create trader',
|
result.message || 'Failed to create trader',
|
||||||
@@ -54,8 +61,9 @@ export const traderApi = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async startTrader(traderId: string): Promise<void> {
|
async startTrader(traderId: string): Promise<void> {
|
||||||
const result = await httpClient.post(
|
const result = await httpClient.request(
|
||||||
`${API_BASE}/traders/${traderId}/start`
|
`${API_BASE}/traders/${traderId}/start`,
|
||||||
|
{ method: 'POST', timeout: TRADER_LIFECYCLE_TIMEOUT_MS }
|
||||||
)
|
)
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
throwApiError(
|
throwApiError(
|
||||||
@@ -117,9 +125,9 @@ export const traderApi = {
|
|||||||
traderId: string,
|
traderId: string,
|
||||||
request: CreateTraderRequest
|
request: CreateTraderRequest
|
||||||
): Promise<TraderInfo> {
|
): Promise<TraderInfo> {
|
||||||
const result = await httpClient.put<TraderInfo>(
|
const result = await httpClient.request<TraderInfo>(
|
||||||
`${API_BASE}/traders/${traderId}`,
|
`${API_BASE}/traders/${traderId}`,
|
||||||
request
|
{ method: 'PUT', data: request, timeout: TRADER_LIFECYCLE_TIMEOUT_MS }
|
||||||
)
|
)
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
throwApiError(
|
throwApiError(
|
||||||
|
|||||||
Reference in New Issue
Block a user