Asynchronous Step Execution

   Journey Manager (JM) The transaction engine for the platform.  |    System Manager / DevOps  |  All versions This feature is related to all versions.

Manager allows you to configure a collaboration job so their steps are executed asynchronously. This enables you to call external services, which return results asynchronously, from the collaboration job without blocking its execution thread. This process is similar to the Job Task Assign and Job Task Wait actions.

A typical asynchronous collaboration job consists of the following three steps.

The Async Invoke Wait step's job definition is shown below:


{
	"name": "Async Invoke Wait",
	"type": "",
	"actions": [
		{
			"name": "AVT-4097 Job Action Invoke",
			"type": "Job Action"
		},
		{
			"name": "Wait For Callback",
			"type": "Job Action Wait"
		}
	],
	"routes": [
		{ "name": "Default",  "nextStep": "Application Completed" }
	]
}

The Async Invoke Wait has two actions configured that allow the following job action state transitions:

Action Service State Initial Run State After Callback
Job Action Invoked Completed
Job Action Wait Pending Completed

Job Action - Call an External Service

The Job Action service is the Groovy service, AVT-4097 Job Action Invoke, is shown below.


def restCallOk = true
ActionResult actionResult = new ActionResult(Status.INVOKED)
// Call rest service
// hand rest failure
if(!restCallOk) {
	actionResult = new ActionResult(Status.IN_PROGRESS)
	// retry in 15 min (service Parameter)
}
return actionResult

The service does the following:

  • Make call to the rest service.
  • If call was successful then set the Action Result to Invoked.
  • If the call fails then set the value to In Progress. The rest call will be tried again in the configured interval in minutes.

Callback

The external system may call back to a Groovy service REST endpoint, which can be generated by a new schedule task or triggered by a submission. In any case, it will get the job action key for the job action that called the external server, for example, the Job Action Invoke completeAction().

The following code is the test Callback implemented with Fluent API, which you can run from the Groovy console to see how collaboration job works.

import com.avoka.tm.svc.JobActionSvc
import com.avoka.tm.vo.Job
import com.avoka.tm.vo.JobAction
import com.avoka.tm.vo.JobStep
import com.avoka.tm.query.JobQuery
import com.avoka.tm.query.JobStepQuery

String jobRef = "QWKJMT7"
Job job = new JobQuery().setReferenceNumber(jobRef).firstValue()
JobStep jobStep = new JobStepQuery().setId(job.currentJobStepId).firstValue()
new JobActionSvc().setJobActionKey(jobStep.jobActions.first().jobActionKey).completeAction()

The callback does the following:

  • Prompts you to enter a job reference code.
  • Locates a collaboration job by a job reference.
  • Looks up the job action key.
  • Finds a job controller service and executes the completeAction() method.

Example 1

To check and change the asynchronous step status:

  1. Run the Form AVT-4097
  2. Open the Job Example 1 form
  3. Fill in your details in the First Name, Last Name, and the Email text field.
  4. Click Submit and record the Reference code.
  5. Locate a collaboration job
  6. Click Edit and select the Actions tab to compare the action statuses
  7. Select the Groovy Script tab and replace jobRef with code from step 1 or 2.
  8. Click Execute Script.
  9. Locate the same collaboration job
  10. Click Edit and select the Actions tab to see that all actions are with the Complete status now.
  11. Click Close.

Download

You can download the complete code example here.

Example 2

  1. Open the AVT-6611 Job Example form.
  2. Click YJFRKCJ.
  3. Select the Transaction Details tab and click the CMQGL8S Collaboration Job
  4. Select the Job Details tab and click the AVT-6611 Combined Wait Action - v1.1.0 Job Controller to check its configuration.
  5. Select the Job Definition tab to check the JSONJSON (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays. configuration.
    {
      "jobDetails": { 
        "name": "AVT-6611 Combined Wait Action",  
        "version": "19.5.0"
      },
      "jobGroups": [
      ],
      "steps": [
        {
          "name": "Application Start",
          "type": "start",
          "actions": [
            {
              "name": "Accept Quote",
              "type": "Job Form Start"
            }
          ],
          "routes": [
            { "name": "Default",  "nextStep": "Async Invoke Wait" }
          ]
        },
        {
          "name": "Async Invoke Wait",
          "type": "",
          "actions": [
            {
              "name": "Assign Review",
              "type": "Job Task Assign",
              "properties": [
                { "name": "Task Assign Groups",  "value": "Job Reviewers" },
                { "name": "Task Form Code",  "value": "$func.startFormCode()" },
                { "name": "Task Message",  "value": "Please review the ${submission.formName} by ${formDataMap.firstName} ${formDataMap.lastName}." },
                { "name": "Task Review Previous Step",  "value": "true" },
                { "name": "Task Subject",  "value": "Review ${submission.formName} by ${submission.contactEmailAddress}." },
                { "name": "Task Type",  "value": "Review" },
                { "name": "Task Enable Claiming",  "value": "true" }
              ]
            },
            {
              "name": "AVT-4097 Job Action Invoke",
              "type": "Job Action"
            },
            {
              "name": "Combined Wait Action",
              "type": "Job Action Wait"
            }
          ],
          "routes": [
            { "name": "Default",  "nextStep": "Application Completed" }
          ]
        },
        {
          "name": "Application Completed",
          "type": "endpoint"
        }
      ]
    }
  6. The first step is Application Start, followed with the Async Invoke Wait step. The later has the Assign Review, AVT-4097 Job Action Invoke, and Combined Wait Action actions. The Combined Wait Action waits for both the Assign Review and AVT-4097 Job Action Invoke to finish before moving to the next, and final, step.

  7. Select the Job Info tab to check what collaboration job's steps were carried out.
  8. Locate the Combined Wait Action - v1.1.0 service.
  9. Select the Groovy Script tab to check the Groovy service.
    import com.avoka.fc.core.entity.JobAction
    import com.avoka.fc.core.entity.JobStep
    import com.avoka.fc.core.service.job.ActionContext
    import com.avoka.fc.core.service.job.ActionResult
    import com.avoka.fc.core.service.job.ActionResult.Status
    import com.avoka.core.groovy.GroovyLogger as logger
    
    /**
     * Combined Wait Action
     *
     * This can be used to combine one or more Asynchronous Actions (Task Wait, Job Action) in the same Step.
     * The wait does not do any routing based upon returned route name (like the Task Wait)
     * It looks at the Action.status to see if the action has been completed.
     * For Tasks it will do an additional check to see if the form is completed.
     *
     */
    JobAction jobAction = actionContext.getJobAction();
    JobStep jobStep = jobAction.getJobStep();
    
    for (JobAction action : jobStep.getOrderedJobActions()) {
        if (action.id != jobAction.id && !action.isStatusCompleted()) {
            return new ActionResult(ActionResult.Status.PENDING)
        }
    }
    
    return new ActionResult(ActionResult.Status.COMPLETED)
  10. Note

    The for loop is the key of this service implementation.

This concludes the example.

Next, learn about one step anonymous review Collaboration Jobs.