Exemplo n.º 1
0
        protected async Task <HttpResponseMessage> ExecuteAsync(int timeoutMs)
        {
            var    log   = new DefaultLogService();
            string input = await Request.Content.ReadAsStringAsync();

            try
            {
                JobsRunner.JobResult result = JobsRunner.Job.RunToCompletion(Path.Combine(basePath, executableName), input, timeoutMs);

                if (result.Errors.Length > 0)
                {
                    var contents = new LogContents(null, result.Errors);
                    faultLogger.Add(DateTime.Now, typeof(JobController).Assembly.GetName().Version.ToString(), input, contents);
                }
                return(HttpResponses.Json(Request, result.Content));
            }
            catch (System.TimeoutException ex)
            {
                RegisterException(faultLogger, log, input, ex);
                return(HttpResponses.PlainText(Request, "Timeout while waiting for the execution to complete", HttpStatusCode.NoContent)); // status 204 if timeout
            }
            catch (Exception ex)
            {
                RegisterException(faultLogger, log, input, ex);
                throw ex;
            }
        }
Exemplo n.º 2
0
        public string Execute(string input, int timeoutMs)
        {
            var log = new DefaultLogService();

            JobsRunner.JobResult result = JobsRunner.Job.RunToCompletion(Path.Combine(basePath, executableName), input, timeoutMs);

            if (result.Errors.Length > 0)
            {
                var contents = new LogContents(null, result.Errors);
                faultLogger.Add(DateTime.Now, typeof(ExeFunctionRunner).Assembly.GetName().Version.ToString(), input, contents);
            }
            return(result.Content);
        }
Exemplo n.º 3
0
        private Stream DoJob(Guid jobId, Stream input)
        {
            Trace.TraceInformation("Doing the job {0}", jobId);
            var sw = new Stopwatch();

            sw.Start();

            string input_s = (new StreamReader(input)).ReadToEnd();

            // JobRunner kills the process, if this thread is aborted due to job cancellation.
            JobsRunner.JobResult result = JobsRunner.Job.RunToCompletion(Path.Combine(basePath, "AnalyzeLTL.exe"), input_s, -1);

            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write(result.Content);
            writer.Flush();
            ms.Position = 0;

            sw.Stop();
            Trace.TraceInformation("Job {0} done ({1})", jobId, sw.Elapsed);

            return(ms);
        }