Skip to content

@codesoul-co/hypha-core / modules/runtime/session-command-scheduler

模块用法

用于执行该边界的运行时行为。Session command scheduler 模块公开 1 类、4 接口。

从包入口导入

ts
import {
  DurableSessionCommandScheduler,
} from '@codesoul-co/hypha-core';

import type {
  DurableSessionCommandSchedulerOptions,
  RunSessionCommandSchedulerRequest,
  SessionCommandProcessor,
  SessionCommandSchedulerResult,
} from '@codesoul-co/hypha-core';

使用要点

  • 4 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 1 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。

公共导出

Symbol种类签名说明
DurableSessionCommandSchedulernew DurableSessionCommandScheduler(options: DurableSessionCommandSchedulerOptions): DurableSessionCommandSchedulerRepeatedly invokes a single-command processor until shutdown is requested. Abort stops new claims, wakes idle waits, and lets an in-flight handler drain.
DurableSessionCommandSchedulerOptions接口interface DurableSessionCommandSchedulerOptionsDurable Session Command Scheduler Options 接口,共包含 7 个公开字段或方法。
RunSessionCommandSchedulerRequest接口interface RunSessionCommandSchedulerRequestRun Session Command Scheduler Request 接口,共包含 2 个公开字段或方法。
SessionCommandProcessor接口interface SessionCommandProcessorSession Command Processor 接口,共包含 1 个公开字段或方法。
SessionCommandSchedulerResult接口interface SessionCommandSchedulerResultSession Command Scheduler Result 接口,共包含 3 个公开字段或方法。

DurableSessionCommandScheduler

Repeatedly invokes a single-command processor until shutdown is requested. Abort stops new claims, wakes idle waits, and lets an in-flight handler drain.

声明

text
export declare class DurableSessionCommandScheduler {
    constructor(options: DurableSessionCommandSchedulerOptions);
    run(request: RunSessionCommandSchedulerRequest): Promise<SessionCommandSchedulerResult>;
}

公开成员

成员种类签名说明
constructor构造函数(options: DurableSessionCommandSchedulerOptions): DurableSessionCommandScheduler创建该类的实例。
run方法run(request: RunSessionCommandSchedulerRequest): Promise<SessionCommandSchedulerResult>公开方法;参数与返回类型以签名列为准。

DurableSessionCommandSchedulerOptions

Durable Session Command Scheduler Options 接口,共包含 7 个公开字段或方法。

声明

text
export interface DurableSessionCommandSchedulerOptions {
    worker: SessionCommandProcessor;
    pollIntervalMs?: number;
    errorBackoffMs?: number;
    shutdownDrainMs?: number;
    wait?: (delayMs: number, signal: AbortSignal) => Promise<void>;
    onResult?: (result: SessionCommandWorkerResult) => void;
    onError?: (error: unknown) => void;
}

契约成员

成员种类签名说明
errorBackoffMs属性errorBackoffMs?: number公开属性;类型、只读和可选状态以签名列为准。
onError方法onError?(error: unknown): void公开方法;参数与返回类型以签名列为准。
onResult方法onResult?(result: SessionCommandWorkerResult): void公开方法;参数与返回类型以签名列为准。
pollIntervalMs属性pollIntervalMs?: number公开属性;类型、只读和可选状态以签名列为准。
shutdownDrainMs属性shutdownDrainMs?: number公开属性;类型、只读和可选状态以签名列为准。
wait方法wait?(delayMs: number, signal: AbortSignal): Promise<void>公开方法;参数与返回类型以签名列为准。
worker属性worker: SessionCommandProcessor公开属性;类型、只读和可选状态以签名列为准。

RunSessionCommandSchedulerRequest

Run Session Command Scheduler Request 接口,共包含 2 个公开字段或方法。

声明

text
export interface RunSessionCommandSchedulerRequest {
    signal: AbortSignal;
    scope?: SessionQueueScope;
}

契约成员

成员种类签名说明
scope属性scope?: SessionQueueScope公开属性;类型、只读和可选状态以签名列为准。
signal属性signal: AbortSignal公开属性;类型、只读和可选状态以签名列为准。

SessionCommandProcessor

Session Command Processor 接口,共包含 1 个公开字段或方法。

声明

text
export interface SessionCommandProcessor {
    processNext(scope?: SessionQueueScope, signal?: AbortSignal): Promise<SessionCommandWorkerResult>;
}

契约成员

成员种类签名说明
processNext方法processNext(scope?: SessionQueueScope, signal?: AbortSignal): Promise<SessionCommandWorkerResult>公开方法;参数与返回类型以签名列为准。

SessionCommandSchedulerResult

Session Command Scheduler Result 接口,共包含 3 个公开字段或方法。

声明

text
export interface SessionCommandSchedulerResult {
    processed: number;
    idlePolls: number;
    errors: number;
}

契约成员

成员种类签名说明
errors属性errors: number公开属性;类型、只读和可选状态以签名列为准。
idlePolls属性idlePolls: number公开属性;类型、只读和可选状态以签名列为准。
processed属性processed: number公开属性;类型、只读和可选状态以签名列为准。