Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel

Table of Contents
maxLevel3

Introduction

In versions prior to 7.1.0.0, Universal Extension task instances could be cancelled via the Controller just like any other task type, but the instances do not participate in the Cancellation process. As a result, there is no chance to do any sort of cleanup before Cancellation. Starting with 7.1.0.0, the Universal Extension API was enhanced with a new method called extension_cancel() which allows for any cleanup work before the process is terminated.

...

  1. Add a new cancel_cleanup_time field to the "UE Task" Universal Template
  2. Add a backing implementation for Cancel Command to the extension.py file.
  3. Build the modified Extension.
  4. Upload the modified Extension.
  5. Demonstrate the Cancel command in three different scenarios
    1. Graceful Cancellation
    2. Timeout
    3. Double Cancel

Step 1 - Add a new "cancel_cleanup_time" field to the "UE Task" Universal Template

Navigate to the "UE Task" Universal Template.

In the "Fields" tab, add a new field called "cancel_cleanup_time" as shown below:

Image RemovedImage Added

The value of this field will be used to simulate the time spent doing the cleanup work in extension_cancel().

Save the field.

Step 2 - Add a backing implementation for Cancel Command to the extension.py file

Open file ~/dev/extensions/sample-task/src/extension.py in your editor of choice.

...

Line 144The cancel_cleanup_time field is extracted from fields and stored in self.cancel_cleanup_time so that it can be accessed in extension_cancel()
Lines 147The extension_start() method is modified to sleep for 45 seconds.
Lines 164-170The extension_cancel() method sleeps for self.cancel_cleanup_time number of seconds. It also logs two statements; one before and one after the sleep time period.

Step 2 - Build and Upload the Extension Zip Archive Using the UIP VS Code Extension

Save all changes to extension.py.

From the VS Code command pallet, execute the UIP: Push command as shown below:

Image RemovedImage Added

Recall that the UIP: Push command builds and uploads the Extension zip archive

...

Expand
titleClick here to expand uip-cli details...

Step 2 Supplemental - Build and Upload the Extension Zip Archive Using the CLI

Save all changes to extension.py.

From the command line, cd to the ~/dev/extensions/sample-task directory and execute the push command as shown below:

Image RemovedImage Added

Recall that the push command builds and uploads the Extension zip archive

Step 3 - Demonstrate Cancel Command

Before working with the Cancel command, we will need to make sure the cancel timeout value (this is NOT the cancel_cleanup_time field above) is set to 10 seconds. Unless you have explicitly modified the value, it will be 10 seconds by default. Open uags.conf, and if there is an entry for extension_cancel_timeout, make sure it is 10 seconds.

a. Graceful Cancellation

Graceful Cancellation is when the extension_cancel() method finishes before the 10 second Cancel timeout period is up.

  • Navigate to the "ue-task-test" task instance form, and ensure the Cancel Cleanup Time field is set to 0 as shown:
    Image RemovedImage Added
  • Launch the task using the VS Code "UIP: Task Launch" command
  • After about 2-3 seconds, right-click the task instance on the Controller and click "Cancel"
  • Wait until the task status is "Cancelled"
  • The entire process should look similar to:

Image RemovedImage Added

Notice that both the log statements were printed since the timeout period of 10 seconds did not expire before the extension_cancel() cleanup finished. 

b. Timeout

Timeout is when the extension_cancel() method has not finished before the 10 second Cancel timeout period is up.

  • Navigate to the "ue-task-test" task instance form, and ensure the Cancel Cleanup Time field is set to 15 as shown:
    Image RemovedImage Added
  • Launch the task using the VS Code "UIP: Task Launch" command
  • After about 2-3 seconds, right-click the task instance on the Controller and click "Cancel"
  • Wait until the task status is "Cancelled"
  • The entire process should look similar to:

Image RemovedImage Added

Notice that only the first log statement was printed. Since the cancel cleanup time value was set to 15 seconds, the Cancel command timed out after 10 seconds, and the Extension process was forcefully terminated.

c. Double Cancel

Double Cancel is when the Extension instance is "Cancelled" twice from the Controller. When the agent receives the second Cancel, it immediately terminates the Extension process regardless of whether the timeout has occurred or not.

  • Navigate to the "ue-task-test" task instance form, and ensure the Cancel Cleanup Time field is set to 15 as shown:
    Image RemovedImage Added
  • Launch the task using the VS Code "UIP: Task Launch" command
  • After about 2-3 seconds, right-click the task instance on the Controller and click "Cancel"
  • Immediately after, right-click the task instance and click "Cancel" once again.
  • The status should immediately transition to "Cancelled"
  • The entire process should look similar to:
    Image RemovedImage Added

Notice that only the first log statement was printed. Since the Extension process was terminated by the Double Cancel before the 15 second sleep period was up, the second log statement did not get printed.

Step 4 - Update the Local template.json

In step 1, we modified the Universal Template by adding the new cancel_cleanup_time field. Recall that inside ~/dev/extensions/sample-task/src/templates, there is a template.json file. This file should correspond to the Universal Template in the Controller. 

Right now, they are not both the same. The Controller's version of template.json has the new field. To grab those changes, use the pull command as shown below:

UIP VS Code Extension

Image RemovedImage AddedImage Removed

Image Added

Expand
titleClick here to expand uip-cli details...

Step Supplemental - CLI

Image RemovedImage Added


Now, both the local and Controller's version of the Universal Template are the same.

...