@hotmeshio/hotmesh
Version:
Serverless Workflow
105 lines (104 loc) • 4.49 kB
TypeScript
import { EngineService } from '../engine';
import { ILogger } from '../logger';
import { StoreService } from '../store';
import { TelemetryService } from '../telemetry';
import { ActivityData, ActivityLeg, ActivityMetadata, ActivityType } from '../../types/activity';
import { ProviderClient, ProviderTransaction, TransactionResultList } from '../../types/provider';
import { JobState, JobStatus } from '../../types/job';
import { StringAnyType } from '../../types/serializer';
import { StreamCode, StreamData, StreamStatus } from '../../types/stream';
/**
* The base class for all activities
*/
declare class Activity {
config: ActivityType;
data: ActivityData;
hook: ActivityData;
metadata: ActivityMetadata;
store: StoreService<ProviderClient, ProviderTransaction>;
context: JobState;
engine: EngineService;
logger: ILogger;
status: StreamStatus;
code: StreamCode;
leg: ActivityLeg;
adjacencyList: StreamData[];
adjacentIndex: number;
constructor(config: ActivityType, data: ActivityData, metadata: ActivityMetadata, hook: ActivityData | null, engine: EngineService, context?: JobState);
setLeg(leg: ActivityLeg): void;
/**
* A job is assumed to be complete when its status (a semaphore)
* reaches `0`. A different threshold can be set in the
* activity YAML, in support of Dynamic Activation Control.
*/
mapStatusThreshold(): number;
/**
* Upon entering leg 1 of a duplexed activity
*/
verifyEntry(): Promise<void>;
/**
* Upon entering leg 2 of a duplexed activity
*/
verifyReentry(): Promise<number>;
processEvent(status?: StreamStatus, code?: StreamCode, type?: 'hook' | 'output'): Promise<void>;
processPending(type: 'hook' | 'output'): Promise<TransactionResultList>;
processSuccess(type: 'hook' | 'output'): Promise<TransactionResultList>;
processError(): Promise<TransactionResultList>;
transitionAdjacent(multiResponse: TransactionResultList, telemetry: TelemetryService): Promise<void>;
resolveStatus(multiResponse: TransactionResultList): number;
mapJobData(): void;
mapInputData(): void;
mapOutputData(): void;
registerTimeout(): Promise<void>;
/**
* Any StreamMessage with a status of ERROR is bound to the activity
*/
bindActivityError(data: Record<string, unknown>): void;
/**
* unhandled activity errors (activities that return an ERROR StreamMessage
* status and have no adjacent children to transition to) are bound to the job
*/
bindJobError(data: Record<string, unknown>): void;
getTriggerConfig(): Promise<ActivityType>;
getJobStatus(): null | number;
setStatus(amount: number, transaction?: ProviderTransaction): Promise<void | any>;
authorizeEntry(state: StringAnyType): string[];
bindDimensionalAddress(state: StringAnyType): void;
setState(transaction?: ProviderTransaction): Promise<string>;
bindJobMetadata(): void;
bindActivityMetadata(): void;
bindJobState(state: StringAnyType): Promise<void>;
bindActivityState(state: StringAnyType): void;
bindJobMetadataPaths(): string[];
bindActivityMetadataPaths(): string[];
getState(): Promise<void>;
/**
* if the job is created/deleted/created with the same key,
* the 'gid' ensures no stale messages (such as sleep delays)
* enter the workstream. Any message with a mismatched gid
* belongs to a prior job and can safely be ignored/dropped.
*/
assertGenerationalId(jobGID: string, msgGID?: string): void;
initDimensionalAddress(dad: string): void;
initSelf(context: StringAnyType): JobState;
initPolicies(context: JobState): void;
bindActivityData(type: 'output' | 'hook'): void;
resolveDad(): string;
resolveAdjacentDad(): string;
filterAdjacent(): Promise<StreamData[]>;
isJobComplete(jobStatus: JobStatus): boolean;
shouldEmit(): boolean;
/**
* emits the job completed event while leaving the job active, allowing
* a `main` thread to exit while other threads continue to run.
* @private
*/
shouldPersistJob(): boolean;
transition(adjacencyList: StreamData[], jobStatus: JobStatus): Promise<string[]>;
/**
* A job with a vale < -100_000_000 is considered interrupted,
* as the interruption event decrements the job status by 1billion.
*/
jobWasInterrupted(jobStatus: JobStatus): boolean;
}
export { Activity, ActivityType };