Пример #1
0
        /// <summary>
        /// Executes a code job, and returns the result.
        /// </summary>
        private async Task <TCodeJobResult> ExecuteCodeJobAsync <TCodeJob, TCodeJobResult>(
            TCodeJob codeJob)
            where TCodeJob : CodeJob
            where TCodeJobResult : CodeJobResult, new()
        {
            var serializedCodeJob = _jsonSerializer.Serialize(codeJob);

            var dockerHost = _dockerHostFactory.CreateDockerHost(c_containerKey);

            var dockerResult = await dockerHost.RunImageInNewContainerAsync(
                serializedCodeJob,
                new Dictionary <string, string>()
            {
                [c_jobTypeVar] = codeJob.GetType().Name.ToCamelCase()
            });

            if (dockerResult.Response == null)
            {
                return(new TCodeJobResult()
                {
                    Status = dockerResult.Completed ? CodeJobStatus.Error : CodeJobStatus.Timeout,
                    DiagnosticOutput = dockerResult.Output
                });
            }

            var codeJobResult = _jsonSerializer.Deserialize <TCodeJobResult>(dockerResult.Response);

            codeJobResult.Status = CodeJobStatus.Completed;

            return(codeJobResult);
        }
Пример #2
0
        /// <summary>
        /// Runs the job, and returns the result.
        /// </summary>
        private async Task <ProjectJobResult> RunJobAsync(ProjectJob projectJob, string operationId)
        {
            var dockerHost = _dockerHostFactory.CreateDockerHost(c_projectRunnerId);

            var jobStarted = _timeProvider.UtcNow;

            var dockerResult = await dockerHost.RunImageInNewContainerAsync(
                requestContents : null,
                environmentVariables : new Dictionary <string, string>()
            {
                [c_githubOAuthTokenVar]         = _config.GitHubOAuthToken,
                [c_githubOrgNameVar]            = projectJob.GitHubOrg,
                [c_projectNameVar]              = projectJob.ProjectName,
                [c_githubSubmissionRepoNameVar] = projectJob.SubmissionRepo,
                [c_githubTemplateRepoNameVar]   = projectJob.TemplateRepo,
                [c_commitShaVar]   = projectJob.CommitSha,
                [c_pathsToCopyVar] = string.Join(";", projectJob.CopyPaths),
                [c_testClassesVar] = string.Join(";", projectJob.TestClasses)
            });

            var jobFinished = _timeProvider.UtcNow;

            List <TestResult> testResults = null;
            bool validResponse            = dockerResult.Completed &&
                                            dockerResult.Response != null &&
                                            TryDeserializeTestResults(dockerResult.Response, out testResults);

            return(new ProjectJobResult()
            {
                BuildRequestToken = projectJob.BuildRequestToken,
                Status = GetProjectJobStatus
                         (
                    dockerResult.Completed,
                    dockerResult.Response != null,
                    validResponse
                         ),
                JobStartedDate = jobStarted,
                JobFinishedDate = jobFinished,
                BuildOutput = dockerResult.Output,
                TestResults = testResults
            });
        }