[BitBucket user: Alain Mazy]
[BitBucket date: 2017-06-08.13:39:02]
note: this might be a duplicate of issue #25 (to be confirmed)
We have a lua scripts that modifies some instances. Thousands of instances are processed correctly but, sometimes, the scripts enters a deadlock.
```
function OnStoredInstance(instanceId, tags, metadata, origin)
-- Ignore the instances that result from a modification to avoid infinite loops
if (metadata['ModifiedFrom'] == nil) then
-- consider only the instances that comes from the Rest API (from a remote orthanc)
if (origin['RequestOrigin'] == 'RestApi') then
print('received an instance from ' .. origin['RemoteIp'])
remoteIp = origin['RemoteIp']
institutionName = tags['InstitutionName']
if institutionName == 'XXX' then
print('received an instance from XXX')
-- Send the modified instance to another modality
SendToModality(instanceId, 'pacs')
else -- YYY does not standardize its InstitutionName yet
print('received an instance from YYY, updating InstitutionName')
institutionName = 'YYY'
local modifyCommand = {}
local replaceTags = {}
replaceTags['InstitutionName'] = institutionName
modifyCommand['Replace'] = replaceTags
-- modify the instance (this will download the modified instance)
local modifiedInstance = RestApiPost('/instances/' .. instanceId .. '/modify', DumpJson(modifyCommand, true))
-- Upload the modified instance to the Orthanc database so that
-- it can be sent by Orthanc to other modalities
local modifiedInstanceId = ParseJson(RestApiPost('/instances/', modifiedInstance)) ['ID']
-- Send the modified instance to another modality
SendToModality(modifiedInstanceId, 'pacs')
print('original id: ' .. instanceId .. ' - modified id: ' .. modifiedInstanceId)
-- Delete the original instance but keep the modified one, it will be deleted by the Orthanc circular buffer
RestApiDelete('/instances/' .. instanceId)
end
end
end
end
```
When getting stuck, it gets stuck between `print('received an instance from YYY, updating InstitutionName')` and `print('original id: ' .. instanceId .. ' - modified id: ' .. modifiedInstanceId)`
|