import type { IActivityHandler } from "@vertigis/workflow"; import axios from "axios"; /** An interface that defines the inputs of the activity. */ interface GetTaskStatusInputs { /** * @displayName job url * @description Job url to get the status of. * @required */ jobUrl: string; /** * @displayName Token * @description Token to access the task. */ token?: string; } /** An interface that defines the outputs of the activity. */ interface GetTaskStatusOutputs { /** * @description The result of the activity. */ result: object; } const getTaskStatus = async (jobUrl: string, token: string) => { const url = `${jobUrl}?f=json&token=${token}`; let jobStatus = 'Processing'; let jobresult = {}; while (jobStatus === 'Processing') { const response = await axios.get(url); jobStatus = response.data.status; jobresult = response.data; await new Promise(resolve => setTimeout(resolve, 1000)); } return jobresult; } /** * @displayName GetTaskStatus * @category Geocortex * @description Get ArcGIS Online Task Status */ export default class GetTaskStatusActivity implements IActivityHandler { /** Perform the execution logic of the activity. */ async execute(inputs: GetTaskStatusInputs): Promise { const result = await getTaskStatus(inputs.jobUrl, inputs.token || ''); return { result: result }; } }