Console icon indicating copy to clipboard operation
Console copied to clipboard

Wait-RemoteSitecoreJob.ps1 "Fails" when Job is finished

Open simoncroak opened this issue 3 years ago • 6 comments

Expected Behavior

When Wait-RemoteSitecoreJob sees that a Job is finished, the scripts should not fail, it should exit gracefully giving an update on the last status of the job

Actual Behavior

Wait-RemoteSitecoreJob fails like this when a job status has "finished":

VERBOSE: Polling job Publish to 'web'. Status : Finished and processed 12035.
VERBOSE: Finished polling job 311ef6f3-ce5c-428a-8829-92f14057ca9a;QACMSWEB1-PJ5.
VERBOSE: Preparing to invoke the script against the service at url https://xxx.xxx.com/-/script/script/?sessionId=e96d0c0d-0e27-48d1-951a-e112d2f724b2&rawOutput=False&persistentSe
ssion=False
VERBOSE: Transferring script to server
VERBOSE: Check that the service files are properly configured.
Invoke-RemoteScript : Server response: The specified script is invalid.
At C:\Program Files\WindowsPowerShell\Modules\SPE\Wait-RemoteSitecoreJob.ps1:87 char:13
+             Invoke-RemoteScript -Session $session -ScriptBlock $finis ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (https://xxx.xxx.com/:) [Write-Error], NotFound
    + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Invoke-RemoteScript
VERBOSE: Stopping from further execution.`

Steps to Reproduce the Problem

Sitecore v10.0.1 SPE v6.3.0

  • [x] Tested issue with clean install of Sitecore and the latest available version of SPE.

  • [ ] Asked questions on the Sitecore Slack Chat channel.

  • [x] Reviewed questions and answers on the Sitecore Stack Exchange.

simoncroak avatar May 25 '22 20:05 simoncroak

I believe this is to do with the fact that the $finishScript here is blank/empty: https://github.com/SitecorePowerShell/Console/blob/fa730e2e0f8a8de55a15adc75e2c5ed2394c7b48/Modules/SPE/Wait-RemoteSitecoreJob.ps1#L54

Yet here it is being passed as part of an Invoke-RemoteScript call: https://github.com/SitecorePowerShell/Console/blob/fa730e2e0f8a8de55a15adc75e2c5ed2394c7b48/Modules/SPE/Wait-RemoteSitecoreJob.ps1#L87

simoncroak avatar May 25 '22 20:05 simoncroak

I suppose returning a 404 for this case doesn't make sense. Probably makes sense to return a 201.

https://github.com/SitecorePowerShell/Console/blob/fa730e2e0f8a8de55a15adc75e2c5ed2394c7b48/src/Spe/sitecore%20modules/PowerShell/Services/RemoteScriptCall.ashx.cs#L664-L669

michaellwest avatar May 25 '22 21:05 michaellwest

My question is more why are we doing this at all? https://github.com/SitecorePowerShell/Console/blob/fa730e2e0f8a8de55a15adc75e2c5ed2394c7b48/Modules/SPE/Wait-RemoteSitecoreJob.ps1#L87

simoncroak avatar May 25 '22 21:05 simoncroak

Probably for consistency. Originally this was written for Wait-RemoteScriptSession. The Wait-RemoteSitecoreJob was for other jobs that run in Sitecore like publishing and indexing. Some users may only ever use Wait-RemoteScriptSession.

https://github.com/SitecorePowerShell/Console/blob/fa730e2e0f8a8de55a15adc75e2c5ed2394c7b48/Modules/SPE/Wait-RemoteScriptSession.ps1#L71-L74

michaellwest avatar May 25 '22 21:05 michaellwest