Example #1
0
        public async Task <ActionResult <string> > NewJob([FromBody] NewJobMessage m)
        {
            var account = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (account == null)
            {
                return(BadRequest());
            }

            FlowSnake id  = FlowSnake.Generate();
            var       job = new Job {
                Id        = id,
                Account   = account,
                Repo      = m.Repo,
                Branch    = m.Ref,
                TestSuite = m.TestSuite,
                Tests     = m.Tests,
                Stage     = JobStage.Queued,
            };

            try {
                var result = await GetRevision(job);

                if (result.isSuccess)
                {
                    job.Revision = result.rev !;
                }
                else
                {
                    return(BadRequest(new ErrorResponse(ErrorCodes.GIT_NO_SUCH_REVISION, result.message)));
                }
                logger.LogInformation("Scheduleing job {0}", job.Id);
                await coordinatorService.ScheduleJob(job);
            } catch (KeyNotFoundException) {
                logger.LogInformation("No such test suite {1} for job {0}", job.Id, job.TestSuite);
                return(BadRequest(new ErrorResponse(ErrorCodes.NO_SUCH_SUITE)));
            } catch (TaskCanceledException) {
                logger.LogInformation("Fetching for job {0} timed out", job.Id);
                return(BadRequest(new ErrorResponse(ErrorCodes.REVISION_FETCH_TIMEOUT)));
            } catch (OutOfActiveTimeException) {
                logger.LogInformation("Fetching for job {0} timed out", job.Id);
                return(BadRequest(new ErrorResponse(ErrorCodes.NOT_IN_ACTIVE_TIMESPAN)));
            }
            return(Ok(id.ToString()));
        }
Example #2
0
        public async Task <IActionResult> NewJob([FromBody] NewJobMessage m)
        {
            var       account = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            FlowSnake id      = FlowSnake.Generate();
            var       job     = new Job
            {
                Id        = id,
                Account   = account,
                Repo      = m.Repo,
                Branch    = m.Ref,
                TestSuite = m.TestSuite,
                Tests     = m.Tests,
                Stage     = JobStage.Queued,
            };

            try {
                var result = await GetRevision(job);

                if (result.isSuccess)
                {
                    job.Revision = result.rev !;
                }
                else
                {
                    return(BadRequest(new ErrorResponse("no_such_revision", result.message)));
                }
                logger.LogInformation("Scheduleing job {0}", job.Id);
                await coordinatorService.ScheduleJob(job);
            } catch (KeyNotFoundException) {
                logger.LogInformation("No such test suite {1} for job {0}", job.Id, job.TestSuite);
                return(BadRequest(new ErrorResponse("no_such_suite")));
            } catch (TaskCanceledException) {
                logger.LogInformation("Fetching for job {0} timed out", job.Id);
                return(BadRequest(new ErrorResponse("revision_fetch_timeout")));
            } catch (OutOfActiveTimeException) {
                logger.LogInformation("Fetching for job {0} timed out", job.Id);
                return(BadRequest(new ErrorResponse("not_in_active_timespan")));
            }
            return(Ok(id.ToString()));
        }