Box CLI with Powershell: How do I wait or check until "operation_blocked_temporary" is gone?
Hello all!
Imagine you are trying to run a Box folder move:
box folders:move sourceID newParentID --as-user=UserID
However, you recently did an action that has that folder "tied up" (such as an owner change).
box : Unexpected API Response [409 Conflict | 5x694sgg41k7x3l0.0e99487b440a063cb504b24ac9647f876] operation_blocked_temporary - The operation is blocked by another
on-going operation
How would I go about doing some sort of check for that error, and waiting until its gone to proceed?
I'm guessing this is dealing with a "Try/Catch" situation? But I can't figure out how to get BOX CLI commands to "catch" at all. No matter what I do, they just error out in the Try and print to screen.
For example, this never triggers the catch, despite giving me a 409 temp block error in the console:
Function move-box-folder {
box folders:move 4***phone number removed for privacy*** --as-user***phone number removed for privacy***
}
try {
move-box-folder -ErrorAction stop
} Catch [System.Exception] {"Caught the exception"}
If I could figure out how to catch, I'm thinking i could put a "if error, sleep 10 min and try again" type of statement.
Or maybe I'm missing something obvious? Some sort of wait() in the command that is triggering the block? Any advice would be appreciated.
-
So I think I've figured a way to do this, but it doesn't use the error message. I have no idea if this is efficient, but it works. Note: I'm still testing this, so I'll update if it fails.
The logic:
- Grab the folder your are moving's (source folder) parent ID. (box folders:get)
- Try the move (Box Folders:Move)
- Grab the source folder's parent ID again. (box folders:get)
- Check if the parent ID now equals the destination folder ID. (Do/Until)
- If not, pause for a while and try again. (start-sleep)
- If it does, then your move was successful and you can move on.
The code example:
#get the parent ID of the source folder for the do until loop $FolderInfo = box folders:get $sourceFolder --as-user=$user --json | ConvertFrom-Json $parentIDofFolder = $FolderInfo.parent.id DO { #Try the move box folders:move $sourceFolder $destinationParentFolder --as-user=$user #Get the parent ID of the folder to see if it moved. If it doesn't match the "destination" location, then it failed. $FolderInfo = box folders:get $sourceFolder --as-user=$user --json | ConvertFrom-Json $parentIDofFolder = $FolderInfo.parent.id Write-Output "ParentID: $parentIDofFolder, ParentID of Destination folder: $destinationParentFolder" If ($parentIDofFolder -eq $destinationParentFolder) { Write-Output "Move complete" } Else { Write-Output "Parent ID did not change. Need to try again. current parentid: $parentIDofFolder. Pausing for 10 min then trying again" Write-Output (get-date).ToString('T') #pause for 10 min. Start-Sleep -s 600 } } Until ($parentIDofFolder -eq $destinationParentFolder)
Note: I'm a BOX CLI and Powershell amateur at best. Accepting all critic and suggestions.
サインインしてコメントを残してください。
コメント
1件のコメント