Skip to main content
Version: Next

GeoprocessingHandler<T, G, P>

Manages the task of executing a geoprocessing function within an AWS Lambda function. This includes sending estimate of completion, caching the results, and getting them back to the client. Supports 2 different execution modes for running a geoprocessing function - sync and async These modes create 3 different request scenarios. A lambda is created for each scenario, and they all run this one handler. 1 - sync executionMode - immediately run gp function and return result in resolved promise to client 2 - async executionMode, ASYNC_REQUEST_TYPE=start - invoke a second lambda to run gp function and return incomplete task to client with socket for notification of result 3 - async executionMode, ASYNC_REQUEST_TYPE=run - run gp function started by scenario 2 and send completed task info on socket for client to pick up result

Type Parameters

Type ParameterDefault typeDescription
TJSONValuethe return type of the geoprocessing function, automatically set from func return type
G extends GeometryPolygon | LineString | Pointthe geometry type of features for the geoprocessing function, automatically set from func feature type
P extends Record<string, JSONValue>Record<string, JSONValue>extra parameters to pass to geoprocessing function, automatically set from func parameter type

Constructors

new GeoprocessingHandler()

new GeoprocessingHandler<T, G, P>(func, options): GeoprocessingHandler<T, G, P>

Parameters

ParameterTypeDescription
func(feature, extraParams, request?) => Promise<T>the geoprocessing function to run
optionsGeoprocessingHandlerOptionsgeoprocessing function deployment options

Returns

GeoprocessingHandler<T, G, P>

new GeoprocessingHandler()

new GeoprocessingHandler<T, G, P>(func, options): GeoprocessingHandler<T, G, P>

Parameters

ParameterType
func(feature, extraParams, request?) => Promise<T>
optionsGeoprocessingHandlerOptions

Returns

GeoprocessingHandler<T, G, P>

Methods

getSocket()

getSocket(wss): Promise<WebSocket>

Returns a new socket connection to send a message

Parameters

ParameterType
wssstring

Returns

Promise<WebSocket>


lambdaHandler()

lambdaHandler(event, context): Promise<APIGatewayProxyResult>

Given request event, runs geoprocessing function and returns APIGatewayProxyResult with task status in the body If sync executionMode, then result is returned with task, if async executionMode, then returns socket for client to listen for task update If event.geometry present, assumes request is already a GeoprocessingRequest (from AWS console). If event.queryStringParameters present, request must be from API Gateway and need to coerce into GeoprocessingRequest If event.body present with JSON string, then parse as a GeoprocessingRequest

Parameters

ParameterType
eventAPIGatewayProxyEvent
contextContext

Returns

Promise<APIGatewayProxyResult>


parseRequest()

parseRequest<G>(event): GeoprocessingRequestModel<G>

Parses event and returns GeoprocessingRequestModel object.

Type Parameters

Type Parameter
G

Parameters

ParameterType
eventAPIGatewayProxyEvent

Returns

GeoprocessingRequestModel<G>


sendSocketErrorMessage()

sendSocketErrorMessage(
wss,
cacheKey,
serviceName,
failureMessage): Promise<void>

Send task error message

Parameters

ParameterType
wssstring
cacheKeyundefined | string
serviceNamestring
failureMessagestring

Returns

Promise<void>


sendSocketMessage()

sendSocketMessage(
wss,
cacheKey,
serviceName): Promise<void>

Send completed task message

Parameters

ParameterType
wssstring
cacheKeyundefined | string
serviceNamestring

Returns

Promise<void>

Properties

func()

func: (feature, extraParams?, request?) => Promise<T>;

Parameters

ParameterTypeDescription
featureFeature<G, GeoJsonProperties> | FeatureCollection<G, GeoJsonProperties> | Sketch<G> | SketchCollection<G>-
extraParams?POptional additional runtime parameters from report client for geoprocessing function. Validation left to implementing function
request?GeoprocessingRequestModel<G>Original event params used to invoke geoprocessing function made accessible to func

Returns

Promise<T>


lastRequestId?

optional lastRequestId: string;

options

options: GeoprocessingHandlerOptions;

Tasks

Tasks: TasksModel;