Wrap results upload in an atomic transaction
When troubleshooting the issue with timeout, I noticed that errors during the processing of results could lead to partial results upload, i.e. only a part of the results are created.
This commit fixes it by running result upload in transactions; now either all writes will succeed or none will. This means if an exception or crash occurs during upload, all results will be discarded.