stock-bot/apps/stock/web-api/src/services/insert-experiment-trial.ts

32 lines
1,023 B
TypeScript

import type { PoolClient } from 'pg';
import type { CanonicalRunRequest } from '@stock-bot/stock-config/canonical-research';
/** Internal persistence step; the caller owns admission, identities, numbering and transaction. */
export async function insertExperimentTrial(
client: PoolClient,
trial: {
runId: string;
backtestId: string;
runNumber: number;
request: CanonicalRunRequest;
experimentId: string;
trialKey: string;
trialIndex: number;
}
): Promise<void> {
await client.query(
`INSERT INTO runs (id,backtest_id,run_number,status,speed_multiplier,request_snapshot,dataset_hash,experiment_id,trial_key,trial_index)
VALUES ($1,$2,$3,'pending',NULL,$4,$5,$6,$7,$8)`,
[
trial.runId,
trial.backtestId,
trial.runNumber,
trial.request,
trial.request.datasetHash,
trial.experimentId,
trial.trialKey,
trial.trialIndex,
]
);
await client.query('INSERT INTO backtest_dispatch (run_id) VALUES ($1)', [trial.runId]);
}