Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 

Web API "ProjectJob - Open" sporadically fails successfully

Web API "ProjectJob - Open" sporadically fails successfully

therusch
Established Member

Hello, 

I am using the ctrlX PLC Engineering Web API (2.4) in a powershell (7) scripting environment. 

I combined the ProjectJobs "Open" and "SaveAndInstallIntoLibraryRepository" in a script. First the project is opened. The status of the Job ID is checked every 6 seconds until it is done, afterwards the library is installed. 
A successful run gives these logs:

#################################
######### OPEN PROJECT ##########
#################################
Open project: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params:  {"jobType":"ProjectJob","jobParameters":{"action": "Open", "path": "C:\\agent\\_work\\8\\s\\Sample.library", "keepProjectVersion": false}}
Open project Job ID: 124d964e073ebbb7
Open project state:  Running
Open project state:  Running
Open project state:  Running
Open project state:  Done
C:\\agent\\_work\\8\\s\\Sample.library opened successfully.
#################################
######## INSTALL PROJECT ########
#################################
Install: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params:  {"jobType":"ProjectJob","jobParameters":{"action": "SaveAndInstallIntoLibraryRepository"}}
Save and Install into library repository Job ID: 22cff790bd9e7762
Save and Install into library repository state:  Done

 

But every other time the same script fails with these logs: 

#################################
######### OPEN PROJECT ##########
#################################
Open project: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params:  {"jobType":"ProjectJob","jobParameters":{"action": "Open", "path": "C:\\agent\\_work\\8\\s\\Sample.library", "keepProjectVersion": false}}
Open project Job ID: 5265406ec5c9666c
Open project state:  Done
C:\\agent\\_work\\8\\s\\Sample.library opened successfully.
#################################
######## INSTALL PROJECT ########
#################################
Install: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params:  {"jobType":"ProjectJob","jobParameters":{"action": "SaveAndInstallIntoLibraryRepository"}}
Save and Install into library repository Job ID: 32ea04d2bd4985ac
Save and Install into library repository state:  Failed
Save and Install into library repository failed.
No open project found.


It is the exact same script. 
It seems, like the Open job returns success, although the project was not opened. 

Does anyone have an idea what can cause this? 

Thank you and best regards

3 REPLIES 3

bostroemc
Occasional Contributor

Have you tried appending to your script a job to close the project?  Does the script behave sporatically then? 

2024-06-11_06h33_51.png

Edit: The script below appears to be working properly for me in ctrlX PLC Engineering 2.6.  

 

$ip_adr = "localhost:9004"

$result = Invoke-WebRequest `
  -Uri http://$ip_adr/plc/engineering/api/v2/jobs `
  -ContentType "application/json" `
  -Method POST `
  -Body '{"jobType":"ProjectJob","jobParameters":{"action": "Open", "path": "C:\\Users\\bostromc\\Desktop\\sample.library", "keepProjectVersion": false}}' `
  | ConvertFrom-Json

$job_id = $result.id
$state = ""
Write-Output $result

while ($state -ne 'Done') {
    start-sleep -seconds 1

    $result = Invoke-WebRequest `
      -Uri http://$ip_adr/plc/engineering/api/v2/jobs/$job_id `
      -ContentType "application/json" `
      -Method GET `
      | ConvertFrom-Json

    Write-Output $result
    $state = $result.state

    if ($state -eq 'Failed') {
        Write-Error 'Invoke-WebRequest failed' -ErrorAction Stop
    }
}

$result = Invoke-WebRequest `
  -Uri http://$ip_adr/plc/engineering/api/v2/jobs `
  -ContentType "application/json" `
  -Method POST `
  -Body '{"jobType":"ProjectJob","jobParameters":{"action": "SaveAndInstallIntoLibraryRepository"}}' `
  | ConvertFrom-Json

$job_id = $result.id
$state = ""

while ($state -ne 'Done') {
    start-sleep -seconds 1

    $result = Invoke-WebRequest `
      -Uri http://$ip_adr/plc/engineering/api/v2/jobs/$job_id `
      -ContentType "application/json" `
      -Method GET `
      | ConvertFrom-Json

    Write-Output $result
    $state = $result.state

    if ($state -eq 'Failed') {
        Write-Error 'Invoke-WebRequest failed' -ErrorAction Stop
    }
}

$result = Invoke-WebRequest `
  -Uri http://$ip_adr/plc/engineering/api/v2/jobs `
  -ContentType "application/json" `
  -Method POST `
  -Body '{"jobType":"ProjectJob","jobParameters":{"action": "Close"}}' `
  | ConvertFrom-Json

pause

 

Note that if a project is already open in ctrlX PLC Engineering when the intial job request is made (i.e. action=open), the job fails as follows:2024-06-11_15h09_46.png

I think this is the correct behaviour.

 

therusch
Established Member

You mean after the SaveAndInstallIntoLibraryRepository Job? 
Not yet, I'll try. 

therusch
Established Member

Hi, 

i added the close job. This job gives the same result as the SaveAndInstallIntoLibraryRepository job. 

#################################
######### CLOSE PROJECT #########
#################################
Close project
Request job with params:  {"jobType":"ProjectJob","jobParameters":{"action": "Close"}}
Close project Job ID: b7525e6698fde56c
Close project state:  Failed
Close project failed.
No open project found.

 

It seems like there is no project open, although ctrlX returns success on the open project job. 

And as mentioned before, I got 2 successful runs before the next failed run. So it works more often than it fails. 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist