Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the
execmanager.retrieve_calculation
idempotent'ish (aiidateam…
…#3142) The `retrieve_calculation` would cause an exception if called multiple times for the same calculations, which can happen if the first time that the runner was working on it got interrupted, for example due to a daemon shutdown. The reason is that the second time around the adding of the `retrieved` folder data node will raise a uniqueness exception, because there can only be one output with the same label. Note that full idempotency is impossible, but this change should make the problem a lot less likely to occur. The idea is to delay the actual attaching of the retrieved folder data node to the last moment possible. This way, if the method is called again and the folder is already there, we can be reasonably sure that the files were already retrieved successfully and we simply return, leaving the call a no-op. This is done in the beginning of the function to check if the output node already exists using the `LinkManager.first()` call. If the node exists, the retrieve function has apparently already been called before and reached the end of the function where it adds the retrieved folder. This means all the files were already successfully retrieved so we can safely skip. The `LinkManager.first()` method is adapted to, instead of raising a `ValueError` when no entry is found at all, simply return `None`. This is more consistent with the behavior of `QueryBuilder.first()`.
- Loading branch information