public static void CreateQueueConsumerThreadBox <T>(string threadboxName, int threadNum, ThreadBoxHandler <T> handler, PopItemMethod <T> method, int milliumsecondSleepTime = 100, bool isStopOnEmptyQueue = false) { if (threadboxName == "" || threadNum <= 0 || handler == null || method == null) { throw new ArgumentException(); } Box b = null; lock (dicBox) { if (dicBox.ContainsKey(threadboxName)) { throw new ArgumentException("threadboxName exist"); } b = new Box(threadNum); dicBox.Add(threadboxName, b); } MethodJob <T> j = new MethodJob <T>(); j.isStop = isStopOnEmptyQueue; j.sleepTime = milliumsecondSleepTime; j.method = method; j.handler = handler; //b.job = j; b.Start(j); }
public async Task ExecuteMethodJobAsync_NoResponse_ReturnsErrorResult() { var dockerHost = GetMockDockerHost ( new DockerResult ( completed: true, output: "DiagnosticOutput", response: null ) ); var methodJob = new MethodJob(); var serializer = GetMockJsonSerializer(methodJob, "SerializedMethodJob"); var codeRunnerService = GetCodeRunnerService ( serializer.Object, dockerHost ); var result = await codeRunnerService.ExecuteMethodJobAsync(methodJob); Assert.Equal(CodeJobStatus.Error, result.Status); Assert.Equal("DiagnosticOutput", result.DiagnosticOutput); }
public async Task ExecuteMethodJobAsync_JobReturnsResponse_ReturnsSuccessResult() { var dockerHost = GetMockDockerHost ( new DockerResult ( completed: true, output: "DiagnosticOutput", response: "SerializedMethodJobResult" ) ); var methodJob = new MethodJob(); var serializer = GetMockJsonSerializer <MethodJob, MethodJobResult> ( methodJob, "SerializedMethodJob", "SerializedMethodJobResult" ); var codeRunnerService = GetCodeRunnerService ( serializer.Object, dockerHost ); var result = await codeRunnerService.ExecuteMethodJobAsync(methodJob); Assert.Equal(CodeJobStatus.Completed, result.Status); Assert.Null(result.DiagnosticOutput); }
public async Task ExecuteMethodJobAsync_MakesCorrectRequest() { var dockerHost = GetMockDockerHost(); var methodJob = new MethodJob(); var serializer = GetMockJsonSerializer(methodJob, "SerializedMethodJob"); var codeRunnerService = GetCodeRunnerService ( serializer.Object, dockerHost ); await codeRunnerService.ExecuteMethodJobAsync(methodJob); Assert.True(dockerHost.RanImage); Assert.Equal("SerializedMethodJob", dockerHost.RequestContents); Assert.Equal(1, dockerHost.EnvironmentVariables.Count); Assert.Equal("methodJob", dockerHost.EnvironmentVariables["JOB_TYPE"]); }
/// <summary> /// Executes a method job. /// </summary> public async Task <MethodJobResult> ExecuteMethodJobAsync(MethodJob methodJob) { return(await ExecuteCodeJobAsync <MethodJob, MethodJobResult>(methodJob, "methodjob")); }
public async Task <CodeJobResult> ExecuteMethodJob([FromBody] MethodJob job) { return(await _codeRunnerService.ExecuteMethodJobAsync(job)); }