public override async Task ProcessJobAsync(IResultSender resultSender)
        {
            using var scope = Logger.BeginScope("Project Adoption ({Id})");

            Logger.LogInformation($"ProcessJob (Adopt) {Id} for project {_projectInfo.Name} started.");

            // upload the file to OSS
            var bucket = await _userResolver.GetBucketAsync(tryToCreate : true);

            ProjectStorage projectStorage = await _userResolver.GetProjectStorageAsync(_projectInfo.Name);

            string ossSourceModel = projectStorage.Project.OSSSourceModel;

            await bucket.SmartUploadAsync(_fileName, ossSourceModel);

            // cleanup before adoption
            File.Delete(_fileName);

            // adopt the project
            bool        adopted = false;
            FdaStatsDTO stats;

            try
            {
                string signedUploadedUrl = await bucket.CreateSignedUrlAsync(ossSourceModel);

                stats = await ProjectWork.AdoptAsync(_projectInfo, signedUploadedUrl);

                adopted = true;
            }
            catch (FdaProcessingException fpe)
            {
                await resultSender.SendErrorAsync(Id, fpe.ReportUrl);

                return;
            }
            finally
            {
                // on any failure during adoption we consider that project adoption failed and it's not usable
                if (!adopted)
                {
                    Logger.LogInformation($"Adoption failed. Removing '{ossSourceModel}' OSS object.");
                    await bucket.DeleteObjectAsync(ossSourceModel);
                }
            }

            Logger.LogInformation($"ProcessJob (Adopt) {Id} for project {_projectInfo.Name} completed.");
            await resultSender.SendSuccessAsync(_dtoGenerator.ToDTO(projectStorage), stats);
        }
Exemple #2
0
        public override async Task ProcessJobAsync(IResultSender resultSender)
        {
            using var scope = Logger.BeginScope("Project Adoption ({Id})");

            try
            {
                var payload = await _adoptProjectWithParametersPayloadProvider.GetParametersAsync(_payloadUrl);

                Logger.LogInformation($"ProcessJob (AdoptProjectWithParameters) {Id} for project {payload.Name} started.");

                var projectWithParameters = await _projectService.AdoptProjectWithParametersAsync(payload);

                Logger.LogInformation($"ProcessJob (AdoptProjectWithParameters) {Id} for project {payload.Name} completed.");

                await resultSender.SendSuccessAsync(projectWithParameters);
            }
            catch (Exception ex)
            {
                await resultSender.SendErrorAsync(new MessagesError(Id, "Adopt project went wrong", new string[] { ex.Message }));
            }
        }