import { IHandlerParameters , ImperativeError } from "@zowe/imperative" ; import { ZosmfBaseHandler } from "@zowe/zosmf-for-zowe-sdk" ; import { PropertiesWorkflow , StartWorkflow , ListWorkflows , IWorkflowInfo } from "@zowe/zos-workflows-for-zowe-sdk" ; /**
 * Common handler to start a workflow instance in z/OSMF.
 * This is not something that is intended to be used outside of this npm package.
 */ export default class WorkflowFullHandler extends ZosmfBaseHandler { private type { * } memberof private arguments : any ; param { IHandlerParameters } params returns { Promise < void > } memberof public async processCmd ( params ) { let error ; this . arguments = params . arguments ; let workflowKey ; if ( this . arguments . workflowKey ) { workflowKey = this . arguments . workflowKey ; } else if ( this . arguments . workflowName ) { workflowKey = await ListWorkflows . getWfKey ( this . mSession , this . arguments . workflowName , undefined ) ; if ( ! workflowKey ) { throw new ImperativeError ( { msg : `No workflows match the provided workflow name.` } ) ; } } try { await StartWorkflow . startWorkflow ( this . mSession , workflowKey , this . arguments . resolveConflict ) ; } catch ( err ) { error = "Start workflow: " + err ; throw error ; } if ( this . arguments . wait ) { let response ; let workflowComplete = false ; while ( ! workflowComplete ) { response = await PropertiesWorkflow . getWorkflowProperties ( this . mSession , workflowKey ) ; if ( response . automationStatus && response . statusName !== "automation-in-progress" ) { workflowComplete = true ; if ( response . statusName === "complete" ) { params . response . data . setObj ( "Complete." ) ; params . response . console . log ( "Workflow completed successfully." ) ; } else { throw new ImperativeError ( { msg : `Workflow failed or was cancelled or there is manual step.` , additionalDetails : JSON . stringify ( response ) } ) ; } } } } else { params . response . data . setObj ( "Started." ) ; params . response . console . log ( "Workflow started." ) ; } } }