@hotmeshio/hotmesh
Version:
Serverless Workflow
138 lines (137 loc) • 8.66 kB
TypeScript
import { KeyStoreParams, KeyType } from '../../../../modules/key';
import { ILogger } from '../../../logger';
import { ActivityType, Consumes } from '../../../../types/activity';
import { AppVID } from '../../../../types/app';
import { HookRule, HookSignal } from '../../../../types/hook';
import { HotMeshApp, HotMeshApps, HotMeshSettings } from '../../../../types/hotmesh';
import { ProviderClient, ProviderTransaction } from '../../../../types/provider';
import { SymbolSets, StringStringType, StringAnyType, Symbols } from '../../../../types/serializer';
import { IdsData, JobStatsRange, StatsType } from '../../../../types/stats';
import { Transitions } from '../../../../types/transition';
import { JobInterruptOptions } from '../../../../types/job';
import { WorkListTaskType } from '../../../../types/task';
import { ThrottleOptions } from '../../../../types/quorum';
import { StoreService } from '../..';
declare abstract class RedisStoreBase<ClientProvider extends ProviderClient, TransactionProvider extends ProviderTransaction> extends StoreService<ClientProvider, TransactionProvider> {
commands: Record<string, string>;
abstract transact(): TransactionProvider;
abstract exec(...args: any[]): Promise<any>;
abstract setnxex(key: string, value: string, expireSeconds: number): Promise<boolean>;
constructor(storeClient: ClientProvider);
init(namespace: string, appId: string, logger: ILogger): Promise<HotMeshApps>;
isSuccessful(result: any): boolean;
delistSignalKey(key: string, target: string): Promise<void>;
zAdd(key: string, score: number | string, value: string | number, redisMulti?: TransactionProvider): Promise<any>;
zRangeByScore(key: string, score: number | string, value: string | number): Promise<string | null>;
mintKey(type: KeyType, params: KeyStoreParams): string;
invalidateCache(): void;
/**
* At any given time only a single engine will
* check for and process work items in the
* time and signal task queues.
*/
reserveScoutRole(scoutType: 'time' | 'signal' | 'activate', delay?: number): Promise<boolean>;
releaseScoutRole(scoutType: 'time' | 'signal' | 'activate'): Promise<boolean>;
getSettings(bCreate?: boolean): Promise<HotMeshSettings>;
setSettings(manifest: HotMeshSettings): Promise<any>;
reserveSymbolRange(target: string, size: number, type: 'JOB' | 'ACTIVITY', tryCount?: number): Promise<[number, number, Symbols]>;
getAllSymbols(): Promise<Symbols>;
getSymbols(activityId: string): Promise<Symbols>;
addSymbols(activityId: string, symbols: Symbols): Promise<boolean>;
seedSymbols(target: string, type: 'JOB' | 'ACTIVITY', startIndex: number): StringStringType;
seedJobSymbols(startIndex: number): StringStringType;
seedActivitySymbols(startIndex: number, activityId: string): StringStringType;
getSymbolValues(): Promise<Symbols>;
addSymbolValues(symvals: Symbols): Promise<boolean>;
getSymbolKeys(symbolNames: string[]): Promise<SymbolSets>;
getApp(id: string, refresh?: boolean): Promise<HotMeshApp>;
setApp(id: string, version: string): Promise<HotMeshApp>;
activateAppVersion(id: string, version: string): Promise<boolean>;
registerAppVersion(appId: string, version: string): Promise<any>;
setStats(jobKey: string, jobId: string, dateTime: string, stats: StatsType, appVersion: AppVID, transaction?: TransactionProvider): Promise<any>;
hGetAllResult(result: any): any;
getJobStats(jobKeys: string[]): Promise<JobStatsRange>;
getJobIds(indexKeys: string[], idRange: [number, number]): Promise<IdsData>;
setStatus(collationKeyStatus: number, jobId: string, appId: string, transaction?: TransactionProvider): Promise<any>;
getStatus(jobId: string, appId: string): Promise<number>;
setState({ ...state }: StringAnyType, status: number | null, jobId: string, symbolNames: string[], dIds: StringStringType, transaction?: TransactionProvider): Promise<string>;
/**
* Returns custom search fields and values.
* NOTE: The `fields` param should NOT prefix items with an underscore.
* NOTE: Literals are allowed if quoted.
*/
getQueryState(jobId: string, fields: string[]): Promise<StringAnyType>;
getState(jobId: string, consumes: Consumes, dIds: StringStringType): Promise<[StringAnyType, number] | undefined>;
getRaw(jobId: string): Promise<StringStringType>;
/**
* collate is a generic method for incrementing a value in a hash
* in order to track their progress during processing.
*/
collate(jobId: string, activityId: string, amount: number, dIds: StringStringType, transaction?: TransactionProvider): Promise<number>;
/**
* Synthentic collation affects those activities in the graph
* that represent the synthetic DAG that was materialized during compilation;
* Synthetic collation distinguishes `re-entry due to failure` from
* `purposeful re-entry`.
*/
collateSynthetic(jobId: string, guid: string, amount: number, transaction?: TransactionProvider): Promise<number>;
setStateNX(jobId: string, appId: string, status?: number): Promise<boolean>;
getSchema(activityId: string, appVersion: AppVID): Promise<ActivityType>;
getSchemas(appVersion: AppVID): Promise<Record<string, ActivityType>>;
setSchemas(schemas: Record<string, ActivityType>, appVersion: AppVID): Promise<any>;
setSubscriptions(subscriptions: Record<string, any>, appVersion: AppVID): Promise<boolean>;
getSubscriptions(appVersion: AppVID): Promise<Record<string, string>>;
getSubscription(topic: string, appVersion: AppVID): Promise<string | undefined>;
setTransitions(transitions: Record<string, any>, appVersion: AppVID): Promise<any>;
getTransitions(appVersion: AppVID): Promise<Transitions>;
setHookRules(hookRules: Record<string, HookRule[]>): Promise<any>;
getHookRules(): Promise<Record<string, HookRule[]>>;
setHookSignal(hook: HookSignal, transaction?: TransactionProvider): Promise<any>;
getHookSignal(topic: string, resolved: string): Promise<string | undefined>;
deleteHookSignal(topic: string, resolved: string): Promise<number | undefined>;
addTaskQueues(keys: string[]): Promise<void>;
getActiveTaskQueue(): Promise<string | null>;
deleteProcessedTaskQueue(workItemKey: string, key: string, processedKey: string, scrub?: boolean): Promise<void>;
processTaskQueue(sourceKey: string, destinationKey: string): Promise<any>;
expireJob(jobId: string, inSeconds: number, redisMulti?: TransactionProvider): Promise<void>;
getDependencies(jobId: string): Promise<string[]>;
/**
* registers a hook activity to be awakened (uses ZSET to
* store the 'sleep group' and LIST to store the events
* for the given sleep group. Sleep groups are
* organized into 'n'-second blocks (LISTS))
*/
registerTimeHook(jobId: string, gId: string, activityId: string, type: WorkListTaskType, deletionTime: number, dad: string, transaction?: TransactionProvider): Promise<void>;
getNextTask(listKey?: string): Promise<[
listKey: string,
jobId: string,
gId: string,
activityId: string,
type: WorkListTaskType
] | boolean>;
/**
* when processing time jobs, the target LIST ID returned
* from the ZSET query can be prefixed to denote what to
* do with the work list. (not everything is known in advance,
* so the ZSET key defines HOW to approach the work in the
* generic LIST (lists typically contain target job ids)
* @param {string} listKey - composite key
*/
resolveTaskKeyContext(listKey: string): [WorkListTaskType, string];
/**
* Interrupts a job and sets sets a job error (410), if 'throw'!=false.
* This method is called by the engine and not by an activity and is
* followed by a call to execute job completion/cleanup tasks
* associated with a job completion event.
*
* Todo: move most of this logic to the engine (too much logic for the store)
*/
interrupt(topic: string, jobId: string, options?: JobInterruptOptions): Promise<void>;
scrub(jobId: string): Promise<void>;
findJobs(queryString?: string, limit?: number, batchSize?: number, cursor?: string): Promise<[string, string[]]>;
findJobFields(jobId: string, fieldMatchPattern?: string, limit?: number, batchSize?: number, cursor?: string): Promise<[string, StringStringType]>;
setThrottleRate(options: ThrottleOptions): Promise<void>;
getThrottleRates(): Promise<StringStringType>;
getThrottleRate(topic: string): Promise<number>;
}
export { RedisStoreBase };