T-104: M1.1 Pass 4a — data-pipeline: read-only 25-date sample-close + USD/CAD reader ({ date: { $in: sampleDates } } over eodPrices / qmPrices / CAD.FOREX) with tests and local benchmark
This commit is contained in:
parent
cf511f05c0
commit
73b34f4c49
3 changed files with 129 additions and 9 deletions
|
|
@ -226,9 +226,11 @@ async function streamSampleCloseFind(
|
|||
onDoc: (doc: unknown) => void
|
||||
): Promise<void> {
|
||||
assertReadOnlyReader(reader);
|
||||
let cursor: ReadOnlySourceSymbolCursor<Record<string, unknown>> | null = null;
|
||||
let closableHandle: Pick<ReadOnlySourceSymbolCursor<Record<string, unknown>>, 'close'> | null =
|
||||
null;
|
||||
let primaryError: unknown = undefined;
|
||||
let hasPrimaryError = false;
|
||||
let isInvalidCursorError = false;
|
||||
|
||||
try {
|
||||
const rawCursor = await reader.find<Record<string, unknown>>(
|
||||
|
|
@ -236,22 +238,31 @@ async function streamSampleCloseFind(
|
|||
filter,
|
||||
findOptions
|
||||
);
|
||||
if (
|
||||
rawCursor !== null &&
|
||||
(typeof rawCursor === 'object' || typeof rawCursor === 'function')
|
||||
) {
|
||||
closableHandle = rawCursor as Pick<
|
||||
ReadOnlySourceSymbolCursor<Record<string, unknown>>,
|
||||
'close'
|
||||
>;
|
||||
}
|
||||
if (Array.isArray(rawCursor) || !isAsyncIterable<Record<string, unknown>>(rawCursor)) {
|
||||
isInvalidCursorError = true;
|
||||
throw new TypeError(
|
||||
`Reader for collection "${collectionName}" must return an incremental AsyncIterable cursor (got buffered or non-async result)`
|
||||
);
|
||||
}
|
||||
cursor = rawCursor as ReadOnlySourceSymbolCursor<Record<string, unknown>>;
|
||||
for await (const doc of cursor) {
|
||||
for await (const doc of rawCursor) {
|
||||
onDoc(doc);
|
||||
}
|
||||
} catch (error) {
|
||||
primaryError = error;
|
||||
hasPrimaryError = true;
|
||||
} finally {
|
||||
if (cursor !== null && typeof cursor.close === 'function') {
|
||||
if (closableHandle !== null && typeof closableHandle.close === 'function') {
|
||||
try {
|
||||
await cursor.close();
|
||||
await closableHandle.close();
|
||||
} catch (closeError) {
|
||||
if (!hasPrimaryError) {
|
||||
primaryError = closeError;
|
||||
|
|
@ -262,7 +273,7 @@ async function streamSampleCloseFind(
|
|||
}
|
||||
|
||||
if (hasPrimaryError) {
|
||||
if (primaryError instanceof TypeError) {
|
||||
if (isInvalidCursorError) {
|
||||
throw primaryError;
|
||||
}
|
||||
throw wrapCollectionReadError(collectionName, primaryError);
|
||||
|
|
@ -286,8 +297,10 @@ function compareFxRates(a: FxRateByDateRecord, b: FxRateByDateRecord): number {
|
|||
* Builds a plain date-first MongoDB `find` filter for Pass 4 sample-close queries:
|
||||
* `{ date: { $in: [...] } }`, optionally AND-ed with `{ eodSearchCode | qmSearchCode: { $in: [...] } }`.
|
||||
*
|
||||
* Both `eodPrices` (`price-storage.ts`) and `qmPrices` (`prices.action.ts`) store `date`
|
||||
* as a `YYYY-MM-DD` string, so `$in` emits sorted `YYYY-MM-DD` strings.
|
||||
* `eodPrices` (`price-storage.ts`) enforces `YYYY-MM-DD` strings for `date`, while
|
||||
* `qmPrices` (`prices.action.ts`) copies the provider's `date` field verbatim (assumed
|
||||
* `YYYY-MM-DD`, with BSON `Date` stored separately in `dateTime`), so `$in` emits sorted
|
||||
* `YYYY-MM-DD` strings.
|
||||
*/
|
||||
export function buildSampleCloseFilter(
|
||||
source: SampleCloseSource,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue