Skip to content

@codesoul-co/hypha-core / modules/runtime/run-lease-store

模块用法

用于持久化并读取该边界的数据。Run lease store 模块公开 1 类、2 函数、1 接口。

从包入口导入

ts
import {
  InMemoryRunLeaseStore,
  runLeaseGuard,
  runLeaseScopeKey,
} from '@codesoul-co/hypha-core';

import type {
  InMemoryRunLeaseStoreOptions,
} from '@codesoul-co/hypha-core';

使用要点

  • 1 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 1 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
  • 2 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。

公共导出

Symbol种类签名说明
InMemoryRunLeaseStorenew InMemoryRunLeaseStore(options?: InMemoryRunLeaseStoreOptions): InMemoryRunLeaseStoreIn Memory Run Lease Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。
runLeaseGuard函数runLeaseGuard(lease: FencedRunLease): { leaseId: string; ownerId: string; fencingToken: number; }Run Lease Guard 函数,提供 1 个公开调用签名;参数与返回类型见下表。
runLeaseScopeKey函数runLeaseScopeKey(scope: RunLeaseScope): stringRun Lease Scope Key 函数,提供 1 个公开调用签名;参数与返回类型见下表。
InMemoryRunLeaseStoreOptions接口interface InMemoryRunLeaseStoreOptionsIn Memory Run Lease Store Options 接口,共包含 1 个公开字段或方法。

InMemoryRunLeaseStore

In Memory Run Lease Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。

声明

text
export declare class InMemoryRunLeaseStore implements RunLeaseStore {
    constructor(options?: InMemoryRunLeaseStoreOptions);
    acquire(request: RunLeaseAcquireRequest): Promise<FencedRunLease | null>;
    preempt(request: RunLeasePreemptRequest): Promise<FencedRunLease>;
    heartbeat(request: RunLeaseHeartbeatRequest): Promise<FencedRunLease>;
    release(request: RunLeaseReleaseRequest): Promise<void>;
    get(scope: RunLeaseScope, checkedAt?: string): Promise<FencedRunLease | null>;
    assertCurrent(request: RunLeaseAssertionRequest): Promise<FencedRunLease>;
}

公开成员

成员种类签名说明
acquire方法acquire(request: RunLeaseAcquireRequest): Promise<FencedRunLease | null>公开方法;参数与返回类型以签名列为准。
assertCurrent方法assertCurrent(request: RunLeaseAssertionRequest): Promise<FencedRunLease>公开方法;参数与返回类型以签名列为准。
constructor构造函数(options?: InMemoryRunLeaseStoreOptions): InMemoryRunLeaseStore创建该类的实例。
get方法get(scope: RunLeaseScope, checkedAt?: string): Promise<FencedRunLease | null>公开方法;参数与返回类型以签名列为准。
heartbeat方法heartbeat(request: RunLeaseHeartbeatRequest): Promise<FencedRunLease>公开方法;参数与返回类型以签名列为准。
preempt方法preempt(request: RunLeasePreemptRequest): Promise<FencedRunLease>公开方法;参数与返回类型以签名列为准。
release方法release(request: RunLeaseReleaseRequest): Promise<void>公开方法;参数与返回类型以签名列为准。

runLeaseGuard

Run Lease Guard 函数,提供 1 个公开调用签名;参数与返回类型见下表。

声明

text
export declare function runLeaseGuard(lease: FencedRunLease): {
    leaseId: string;
    ownerId: string;
    fencingToken: number;
};

调用签名

text
runLeaseGuard(lease: FencedRunLease): { leaseId: string; ownerId: string; fencingToken: number; }

参数

参数类型必需说明
leaseFencedRunLease必需参数;接受的值由类型列定义。

返回值

  • 类型: { leaseId: string; ownerId: string; fencingToken: number; }
  • 说明: 返回值契约由上述类型定义。

runLeaseScopeKey

Run Lease Scope Key 函数,提供 1 个公开调用签名;参数与返回类型见下表。

声明

text
export declare function runLeaseScopeKey(scope: RunLeaseScope): string;

调用签名

text
runLeaseScopeKey(scope: RunLeaseScope): string

参数

参数类型必需说明
scopeRunLeaseScope必需参数;接受的值由类型列定义。

返回值

  • 类型: string
  • 说明: 返回值契约由上述类型定义。

InMemoryRunLeaseStoreOptions

In Memory Run Lease Store Options 接口,共包含 1 个公开字段或方法。

声明

text
export interface InMemoryRunLeaseStoreOptions {
    now?: () => string;
}

契约成员

成员种类签名说明
now方法now?(): string公开方法;参数与返回类型以签名列为准。