UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

83 lines (82 loc) 3.03 kB
import { APIGatewayProxyResult } from "aws-lambda"; import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb"; export declare const commonHeaders: { "Access-Control-Allow-Origin": string; "Access-Control-Allow-Credentials": boolean; "Cache-Control": string; }; export interface GeoprocessingTask<ResultType = any> { id: string; service: string; location: string; startedAt: string; duration?: number; logUriTemplate: string; geometryUri: string; status: GeoprocessingTaskStatus; /** websocket url */ wss: string; data?: ResultType; error?: string; estimate: number; disableCache?: boolean; } export interface MetricGroupItem<ResultType = any> { duration?: number; status: GeoprocessingTaskStatus; data?: ResultType; } export interface RootTaskItem<ResultType = any> extends MetricGroupItem<ResultType> { metricGroupItems: string[]; } export declare enum GeoprocessingTaskStatus { Pending = "pending", Completed = "completed", Failed = "failed" } /** * Task model responsible for managing task results and estimates in DynamoDB */ export default class TasksModel { /** task table */ table: string; /** task estimate table */ estimatesTable: string; /** database client */ db: DynamoDBDocument; constructor(table: string, estimatesTable: string, db: DynamoDBDocument); init(service: string, id?: string, /** websocket url */ wss?: string, startedAt?: string, duration?: number, status?: GeoprocessingTaskStatus): GeoprocessingTask<any>; create(service: string, options?: { /** Unique identifier for this task, used as cache key. If not provided a uuid is created */ id?: string; /** websocket url */ wss?: string; disableCache?: boolean; }): Promise<GeoprocessingTask<any>>; /** * @param task * @param results - JSON serializable object, with no string larger than 400KB without a space character. Spaces are used to chunk result * @param options * @returns */ complete(task: GeoprocessingTask, results: any, options?: { minSplitSizeBytes?: number; }): Promise<APIGatewayProxyResult>; updateEstimate(task: GeoprocessingTask): Promise<number | undefined>; fail(task: GeoprocessingTask, errorDescription: string, error?: Error): Promise<APIGatewayProxyResult>; get(service: string, taskId: string): Promise<GeoprocessingTask | undefined>; getMeanEstimate(task: GeoprocessingTask): Promise<number>; /** * Transform valid JSON object into string and break into pieces no larger than minSplitSizeBytes * @param rootResult * @param minSplitSizeBytes maximum return substring size in bytes (default 350KB, below 400KB dynamodb limit) * @returns array of JSON substrings, in order for re-assembly */ private toJsonStrings; /** * Given array of partial JSON strings, joins them together and parses the result */ private fromJsonStrings; }