Exemplo n.º 1
0
        public string Build()
        {
            try
            {
                // CREATING
                _buildAtom(this);

                // CREATED
                CreateAtomState();

                // RUN
                _client.ChangeState(_atomId, _initialState);
            }
            catch
            {
                // FULL CLEANUP IN CASE OF FAIL
                foreach (var createdJobId in _createdSubAtoms)
                {
                    _client.Delete(createdJobId.Key);
                }

                using (var connection = _jobStorage.GetJobStorageConnection())
                {
                    using var tr = connection.CreateJobStorageTransaction();
                    tr.RemoveSet(Atom.GenerateSubAtomKeys(_atomId));
                    var atomRemainingKeys = Atom.GenerateSubAtomRemainingKeys(_atomId);
                    foreach (var activeSubatoms in _createdSubAtoms.Where(x => !x.Value.IsFinal))
                    {
                        tr.RemoveFromSet(atomRemainingKeys, activeSubatoms.Key);
                    }
                    tr.Commit();
                }

                _client.Delete(_atomId);
                throw;
            }

            return(_atomId);
        }