예제 #1
0
        private async Task ArchiveTask(NextPipeTask task)
        {
            var insertSuccessful = false;
            var archiveId        = new Id();

            // First try to archive to prevent data loss
            try
            {
                await _archiveRepository.Insert(new ArchiveObject
                {
                    Id              = archiveId.Value,
                    Type            = NextPipeObjectType.NextPipeTask,
                    TypeReferenceId = task.Id,
                    ArchiveReason   = ReasonForArchive.TaskCompleted,
                    Metadata        = task
                });

                insertSuccessful = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                insertSuccessful = false;
            }

            if (insertSuccessful)
            {
                try
                {
                    await _tasksRepository.Delete(task.Id);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    await _archiveRepository.Delete(archiveId.Value);
                }
            }
        }