docs: explain strategy replay and durable execution code
This commit is contained in:
parent
8587c71cf3
commit
dd7ac53c51
19 changed files with 494 additions and 41 deletions
|
|
@ -1,6 +1,11 @@
|
|||
import type { Logger, PostgresClient, Queue } from '@stock-bot/services';
|
||||
|
||||
/** PostgreSQL is the source of truth; Redis jobs are repeatable delivery notifications. */
|
||||
/**
|
||||
* Bridges committed backtest_dispatch rows to BullMQ and recovers expired leases.
|
||||
* PostgreSQL is the source of truth; Redis jobs are repeatable notifications.
|
||||
* Duplicate delivery is safe because BacktestRunner must claim the SQL run before
|
||||
* executing it. Queue retries and durable attempt limits are separate mechanisms.
|
||||
*/
|
||||
export class BacktestDispatcher {
|
||||
private timer?: ReturnType<typeof setInterval>;
|
||||
private inFlight?: Promise<void>;
|
||||
|
|
@ -27,6 +32,7 @@ export class BacktestDispatcher {
|
|||
);
|
||||
}
|
||||
|
||||
/** Timer/manual ticks share one in-flight pass; a slow publish cannot overlap itself. */
|
||||
tick(): Promise<void> {
|
||||
if (this.closing) {
|
||||
return Promise.resolve();
|
||||
|
|
@ -44,6 +50,11 @@ export class BacktestDispatcher {
|
|||
await this.inFlight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover SQL ownership first, reserve due notifications second, publish last.
|
||||
* next_publish_at is a retry delay, not a delivery acknowledgement: a crash
|
||||
* after reservation leaves a durable intent that becomes due again.
|
||||
*/
|
||||
private async dispatch() {
|
||||
// Recovery is independent of Redis availability. Every terminal write fences the old owner.
|
||||
await this.postgres.transaction(async client => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue