Citrix MCS may take several hours to delete failed tasks

Citrix MCS may take several hours to delete failed tasks

book

Article ID: CTX583783

calendar_today

Updated On:

Description

Citrix MCS may take several hours to delete failed VM creation tasks.
 

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.

Resolution

You can follow steps below to terminate the Unused Image Cleanup task.
There are two ways to do this, either of which has same effect.

Scenario 1:

  1. Execute get-provtask command to obtain TaskId of unused image cleanup task. (Remember the TaskId. This value is used for ScopeID).

Get-ProvTask -Type DisusedImageCleanUp

  1. Check tasks in the DesktopUpdateManagerSchema, Workflow table and change the value to IsComplete. Update DesktopUpdateManagerSchema.Workflow set is complete = 1 where ScopeID = 'TaskId get from step1'

  2. Execute following command to terminate the task.

Get-ProvTask | where {$_.Type -eq "DisusedImageCleanup" -and $_.Status -ne "Finished"} | Stop-ProvTask


Scenario 2:

  1. Execute "get-provtask" command to obtain TaskId of  "DisusedImageCleanup" task. (Remember the TaskId. This value is used for InstanceKey)

Get-ProvTask -Type DisusedImageCleanUp

  1. Check task in the DesktopUpdateManagerSchema, Activity table and change the value to IsComplete. Update DesktopUpdateManagerSchema.Activity set is complete = 1 where InstanceKey = 'TaskId obtained from step 1'.

  2. Execute following command to terminate the task.

Get-ProvTask|where {$_.Type -eq "DisusedImageCleanup" -and $_.WorkflowStatus -eq "Terminated"}|Remove-ProvTask



A computer screen with a blue background  Description automatically generated

Note:  Please ensure that commands are tested before use.


Problem Cause

Stop-provtask queries the database according to the task ID parameter if the task is active, it will call MS API to terminate. This takes a long time.
This task can be changed to inactive to delete it.

 
 

Additional Information

Get-ProvTask
https://developer-docs.citrix.com/en-us/citrix-virtual-apps-desktops-sdk/current-release/MachineCreation/Get-ProvTask/