Exemplo n.º 1
0
        public async Task <IActionResult> UpdateProcedureExecutionStatus([FromRoute] string procedureName, [FromRoute] string projectName,
                                                                         [FromRoute] string revisionNumber, [FromRoute] string status, [FromBody] JobStatusRequest jobStatus)
        {
            Project project = await ProjectDataService.GetAsync(TableStorageConfig.DomainString, projectName);

            if (project == null)
            {
                return(Unauthorized());
            }

            Revision revision = await RevisionDataService.GetAsync(projectName, revisionNumber);

            if (revision == null)
            {
                revision = new Revision()
                {
                    ProjectName    = projectName,
                    RevisionNumber = revisionNumber,
                    Requestor      = "",
                    CommitSet      = jobStatus.CommitSet,
                    CommitPayload  = JsonSerializer.Serialize(jobStatus.Commit),
                    CreatedTime    = DateTimeOffset.Now
                };
                await RevisionDataService.InsertAsync(revision);
            }
            else
            {
                revision.CommitPayload = JsonSerializer.Serialize(jobStatus.Commit);
                await RevisionDataService.UpdateAsync(revision);
            }

            Procedure procedure = await ProcedureDataService.GetAsync(projectName, procedureName);

            if (procedure == null)
            {
                procedure = new Procedure(projectName, procedureName)
                {
                    CreatedTime = DateTimeOffset.Now,
                    LongName    = procedureName
                };
                await ProcedureDataService.InsertAsync(procedure);
            }

            // Update status
            ProcedureExecution procedureExecution = new ProcedureExecution(revisionNumber, jobStatus.JobId, procedureName,
                                                                           JsonSerializer.Serialize(jobStatus.CiConfiguration), status)
            {
                DownloadLink = jobStatus.DownloadLink,
                ConsoleLog   = jobStatus.ConsoleLog,
                Machine      = jobStatus.Machine
            };
            await ProcedureExecutionDataService.InsertOrReplaceAsync(projectName, procedureExecution);

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateProcedureExecutionStatus([FromRoute] string procedureName, [FromRoute] string projectName,
                                                                         [FromRoute] string revisionNumber, [FromRoute] string status, [FromBody] JobStatusRequest jobStatus)
        {
            Project project = await ProjectDataService.GetAsync(TableStorageConfig.DomainString, projectName);

            if (project == null)
            {
                return(Unauthorized());
            }

            var tasks = new List <Task>();

            Revision revision = await RevisionDataService.GetAsync(projectName, revisionNumber);

            if (revision == null)
            {
                revision = new Revision()
                {
                    ProjectName    = projectName,
                    RevisionNumber = revisionNumber,
                    Requestor      = "",
                    CommitSet      = jobStatus.CommitSet,
                    CommitPayload  = JsonSerializer.Serialize(jobStatus.Commit),
                    CreatedTime    = DateTimeOffset.Now
                };
                tasks.Add(RevisionDataService.InsertAsync(revision));
            }
            else
            {
                revision.CommitPayload = JsonSerializer.Serialize(jobStatus.Commit);
                tasks.Add(RevisionDataService.UpdateAsync(revision));
            }

            Procedure procedure = await ProcedureDataService.GetAsync(projectName, procedureName);

            if (procedure == null)
            {
                procedure = new Procedure(projectName, procedureName)
                {
                    CreatedTime = DateTimeOffset.Now,
                    LongName    = procedureName
                };
                tasks.Add(ProcedureDataService.InsertAsync(procedure));
            }

            // Update status
            ProcedureExecution procedureExecution = new ProcedureExecution(revisionNumber, jobStatus.JobId, procedureName,
                                                                           JsonSerializer.Serialize(jobStatus.CiConfiguration), status)
            {
                DownloadLink = jobStatus.DownloadLink,
                ConsoleLog   = jobStatus.ConsoleLog,
                Machine      = jobStatus.Machine
            };

            tasks.Add(ProcedureExecutionDataService.InsertOrReplaceAsync(projectName, procedureExecution));

            // Make sure all changes from database are done before trigger event to clients
            await Task.WhenAll(tasks).ContinueWith(async(antecedent) =>
            {
                await BroadcastStatusHubContext.Clients.All.SendAsync(EventTable.GetEventMessage(EventTable.EventID.EventProcedureExecutionStatusChanged), projectName, revision, procedureExecution);
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            return(Ok());
        }