Ejemplo n.º 1
0
 public IList <BatchRunResult> GetResults(BatchRun batchRun)
 {
     return(GetResultsQuery(batchRun)
            .OrderBy(result => result.ExecutionOrder)
            .Asc.Cacheable()
            .List());
 }
Ejemplo n.º 2
0
        public NextJobToRunResult Get(BatchRun batchRun)
        {
            if (batchRun.Status == BatchRunStatus.Pending)
            {
                return(new NextJobToRunResult());
            }
            if (batchRun.Status == BatchRunStatus.Complete)
            {
                return new NextJobToRunResult {
                           Complete = true
                }
            }
            ;
            if (batchRun.Status == BatchRunStatus.Paused)
            {
                return new NextJobToRunResult {
                           Paused = true
                }
            }
            ;

            BatchRunResult runResult = _session.QueryOver <BatchRunResult>()
                                       .Where(result => result.Status == JobExecutionStatus.Pending && result.BatchRun.Id == batchRun.Id)
                                       .OrderBy(result => result.ExecutionOrder).Asc
                                       .Take(1).SingleOrDefault();

            return(runResult == null ? new NextJobToRunResult {
                Complete = true
            } : new NextJobToRunResult {
                Result = runResult
            });
        }
    }
}
Ejemplo n.º 3
0
        public BatchCreationResult Create(IEnumerable <BatchJob> jobs)
        {
            DateTime now = CurrentRequestData.Now;
            // we need to make sure that the site is loaded from the correct session
            var site  = _statelessSession.Get <Site>(_site.Id);
            var batch = new Batch
            {
                BatchJobs = new List <BatchJob>(),
                BatchRuns = new List <BatchRun>(),
                Site      = site,
                CreatedOn = now,
                UpdatedOn = now
            };

            _statelessSession.Transact(session => session.Insert(batch));
            _statelessSession.Transact(session =>
            {
                foreach (BatchJob job in jobs)
                {
                    job.CreatedOn = now;
                    job.UpdatedOn = now;
                    job.Site      = site;
                    job.Batch     = batch;

                    batch.BatchJobs.Add(job);
                    session.Insert(job);
                }
            });
            BatchRun batchRun = _createBatchRun.Create(batch);

            batch.BatchRuns.Add(batchRun);
            _statelessSession.Transact(session => session.Update(batch));

            return(new BatchCreationResult(batch, batchRun));
        }
Ejemplo n.º 4
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            tbStartTime.Text = DateTime.Now.ToString();
            tbEndTime.Text   = "";
            int      path = int.Parse(tbPath.Text);
            int      numberOfIntervals = int.Parse(tbNumberOfIntervals.Text);
            DateTime createDate        = new DateTime();


            batchRun                   = new BatchRun();
            batchRun.BatchRunId        = BatchRunManager.GetMaxBatchRunId() + 1;
            batchRun.NumberOfIntervals = numberOfIntervals;
            batchRun.Path              = path;


            StatisticsManager.GenerateBatchRunHistograms(batchRun);
            createDate          = DateTime.Now;
            batchRun.CreateDate = createDate;

            BatchRunManager.InsertOneBatchRun(batchRun);
            BatchRunManager.GetBatchRunMeanProfit(batchRun);
            List <BatchRun> batchRuns = BatchRunManager.GetAllBatchRun();

            dgBatchRun.DataSource = batchRuns;
            dgBatchRun.Columns["NumberOfIntervals"].Visible = false;

            //List<BatchRunHistogram> batchRunHistograms = BatchRunHistogramManager.GetBatchRunHistograms(batchRun.BatchRunId);
            //dgHistogram.DataSource = batchRunHistograms;

            this.timerCheckTaskStatus.Start();
        }
Ejemplo n.º 5
0
        public async Task <bool> Execute(BatchRun batchRun)
        {
            Stopwatch          stopWatch = Stopwatch.StartNew();
            NextJobToRunResult result    = _getNextJobToRun.Get(batchRun);
            BatchRunResult     runResult = result.Result;

            if (runResult == null)
            {
                if (result.Complete)
                {
                    _setRunStatus.Complete(batchRun);
                }
                if (result.Paused)
                {
                    _setRunStatus.Paused(batchRun);
                }
                return(false);
            }

            if (runResult.BatchJob == null)
            {
                _setBatchJobExecutionStatus.Complete(runResult,
                                                     BatchJobExecutionResult.Failure("No job associated to result"));
            }

            await _runBatchRunResult.Run(runResult, stopWatch);

            return(true);
        }
Ejemplo n.º 6
0
        public static List <BatchRun> GetAllBatchRun()
        {
            string          connStr   = ConfigurationManager.AppSettings["connStr"];
            string          sCommand  = "Select * from BatchRun";
            List <BatchRun> batchRuns = new List <BatchRun>();

            using (SqlConnection sConnect = new SqlConnection(connStr))
            {
                using (SqlCommand sqlCommand = new SqlCommand(sCommand, sConnect))
                {
                    sConnect.Open();
                    SqlDataReader sr = sqlCommand.ExecuteReader();

                    while (sr.Read())
                    {
                        BatchRun batchRun = new BatchRun();
                        batchRun.BatchRunId = int.Parse(sr["BatchRunId"].ToString());
                        batchRun.CreateDate = DateTime.Parse(sr["CreateDate"].ToString());
                        batchRun.Path       = int.Parse(sr["Path"].ToString());
                        batchRun.ProfitMean = double.Parse(sr["ProfitMean"].ToString());
                        batchRuns.Add(batchRun);
                    }
                }
            }
            return(batchRuns);
        }
Ejemplo n.º 7
0
 private void SetStatus(BatchRun batchRun, BatchRunStatus status)
 {
     _session.Transact(session =>
     {
         batchRun.Status = status;
         session.Update(batchRun);
     });
 }
Ejemplo n.º 8
0
 public async Task Execute(BatchRun run)
 {
     // ensure the run is from the current session
     run        = _session.Get <BatchRun>(run.Id);
     run.Status = BatchRunStatus.Executing;
     while (await _executeNextBatchJob.Execute(run))
     {
     }
 }
Ejemplo n.º 9
0
        public async Task <JsonResult> ExecuteNext([IoCModelBinder(typeof(BatchRunGuidModelBinder))] BatchRun run)
        {
            int?result = run == null ? null : await _batchRunUIService.ExecuteNextTask(run);

            if (result != null)
            {
                _batchRunUIService.ExecuteRequestForNextTask(run);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 10
0
 public static object ToSimpleJson(this BatchRun batchRun, BatchCompletionStatus completionStatus)
 {
     return(new
     {
         guid = batchRun.Guid,
         id = batchRun.Id,
         status = batchRun.Status.ToString(),
         completionStatus
     });
 }
Ejemplo n.º 11
0
        private IQueryOver <BatchRunResult, BatchRunResult> GetResultsQuery(BatchRun batchRun)
        {
            IQueryOver <BatchRunResult, BatchRunResult> queryOver = _session.QueryOver <BatchRunResult>();

            if (batchRun != null)
            {
                return(queryOver.Where(result => result.BatchRun.Id == batchRun.Id));
            }
            // query to return 0;
            return(queryOver.Where(result => result.Id < 0));
        }
Ejemplo n.º 12
0
        public void Execute(OnUpdatedArgs <BatchRunResult> args)
        {
            IHubContext    hubContext     = GlobalHost.ConnectionManager.GetHubContext <BatchProcessingHub>();
            BatchRunResult batchRunResult = args.Item;

            hubContext.Clients.All.updateResult(batchRunResult.Id);
            BatchRun batchRun = batchRunResult.BatchRun;

            hubContext.Clients.All.updateRun(batchRun.ToSimpleJson(_batchRunUIService.GetCompletionStatus(batchRun)));
            hubContext.Clients.All.updateJob(batchRunResult.BatchJob.Id);
        }
Ejemplo n.º 13
0
        public BatchCompletionStatus GetCompletionStatus(BatchRun batchRun)
        {
            IFutureValue <decimal?> timeTaken =
                GetResultsQuery(batchRun)
                .Where(result => result.MillisecondsTaken != null)
                .Select(Projections.Sum <BatchRunResult>(result => result.MillisecondsTaken))
                .Cacheable()
                .FutureValue <decimal?>();
            IFutureValue <double?> averageTimeTaken =
                GetResultsQuery(batchRun)
                .Where(result => result.MillisecondsTaken != null)
                .Select(Projections.Avg <BatchRunResult>(result => result.MillisecondsTaken))
                .Cacheable()
                .FutureValue <double?>();
            IFutureValue <int> pending =
                GetResultsQuery(batchRun)
                .Where(result => result.Status == JobExecutionStatus.Pending)
                .Select(Projections.Count <BatchRunResult>(result => result.Id))
                .Cacheable()
                .FutureValue <int>();
            IFutureValue <int> failed =
                GetResultsQuery(batchRun)
                .Where(result => result.Status == JobExecutionStatus.Failed)
                .Select(Projections.Count <BatchRunResult>(result => result.Id))
                .Cacheable()
                .FutureValue <int>();
            IFutureValue <int> succeeded =
                GetResultsQuery(batchRun)
                .Where(result => result.Status == JobExecutionStatus.Succeeded)
                .Select(Projections.Count <BatchRunResult>(result => result.Id))
                .Cacheable()
                .FutureValue <int>();
            IFutureValue <int> total =
                GetResultsQuery(batchRun)
                .Select(Projections.Count <BatchRunResult>(result => result.Id))
                .Cacheable()
                .FutureValue <int>();


            double averageTime   = averageTimeTaken.Value.GetValueOrDefault();
            int    pendingNumber = pending.Value;

            return(new BatchCompletionStatus
            {
                Total = total.Value,
                Failed = failed.Value,
                Pending = pendingNumber,
                Succeeded = succeeded.Value,
                TimeTaken = TimeSpan.FromMilliseconds(Convert.ToDouble(timeTaken.Value.GetValueOrDefault())),
                AverageTimeTaken = averageTime.ToString("0.00ms"),
                EstimatedTimeRemaining = TimeSpan.FromMilliseconds(averageTime * pendingNumber)
            });
        }
        public void Execute(BatchRun run)
        {
            var httpClient  = new HttpClient();
            var routeValues = new RouteValueDictionary
            {
                { "id", run.Guid },
                { "area", "" },
                { _siteSettings.TaskExecutorKey, _siteSettings.TaskExecutorPassword }
            };
            string url = _urlHelper.Action("ExecuteNext", "BatchExecution", routeValues, "http");

            httpClient.GetAsync(url);
        }
Ejemplo n.º 15
0
        public static void GenerateBatchRunHistograms(BatchRun batchRun)
        {
            ScenarioResult scenarioResult = new ScenarioResult();


            List <Task> tasks = new List <Task>();

            Task task1 = new Task(() =>
            {
                for (int i = 0; i < batchRun.Path; i++)
                {
                    Task task = new Task(() =>
                    {
                        int localCount = i;
                        scenarioResult = ScenarioGenerationManager.ScenarioGeneration();
                        ScenarioResultManager.InsertOneScenarioResult(scenarioResult);

                        IncrementFinishedThreadCount(localCount);
                    });

                    task.Start();
                    tasks.Add(task);
                }
            });

            task1.Start();
            //task1.Wait();
            //for (int i = 0; i < batchRun.Path; i++)
            //{
            //    tasks[i].Wait();
            //}



            //Parallel.For(0, batchRun.Path, index =>
            //{
            //    scenarioResult = ScenarioGenerationManager.ScenarioGeneration();
            //    ScenarioResultManager.InsertOneScenarioResult(scenarioResult);
            //});

            /*
             * for(int i = 0; i < batchRun.Path; i++)
             * {
             *  scenarioResult = ScenarioGenerationManager.ScenarioGeneration();
             *  ScenarioResultManager.InsertOneScenarioResult(scenarioResult);
             * }
             */


            //BatchRunHistogramManager.GenerateHistogram(batchRun);
        }
Ejemplo n.º 16
0
        public BatchRun Create(Batch batch)
        {
            if (batch == null)
            {
                return(null);
            }
            BatchJob jobAlias = null;

            var subQuery = QueryOver.Of <BatchRunResult>()
                           .Where(result => result.Status != JobExecutionStatus.Failed && result.BatchJob.Id == jobAlias.Id)
                           .Select(result => result.Id);

            var jobs = _statelessSession.QueryOver(() => jobAlias)
                       .Where(job => job.Batch.Id == batch.Id)
                       .WithSubquery.WhereNotExists(subQuery)
                       .List();

            // we need to make sure that the site is loaded from the correct session
            var site = _statelessSession.Get <Site>(batch.Site.Id);

            return(_statelessSession.Transact(session =>
            {
                var now = CurrentRequestData.Now;
                var batchRun = new BatchRun
                {
                    Batch = batch,
                    BatchRunResults = new List <BatchRunResult>(),
                    Site = site,
                    CreatedOn = now,
                    UpdatedOn = now
                };
                session.Insert(batchRun);
                for (int index = 0; index < jobs.Count; index++)
                {
                    BatchJob batchJob = jobs[index];
                    var batchRunResult = new BatchRunResult
                    {
                        BatchJob = batchJob,
                        Status = JobExecutionStatus.Pending,
                        ExecutionOrder = index,
                        BatchRun = batchRun,
                        Site = site,
                        CreatedOn = now,
                        UpdatedOn = now
                    };
                    batchRun.BatchRunResults.Add(batchRunResult);
                    session.Insert(batchRunResult);
                }
                return batchRun;
            }));
        }
Ejemplo n.º 17
0
        public void Execute(BatchRun run)
        {
            CookieContainer      cookieContainer = new CookieContainer();
            HttpCookieCollection cookies         = _context.Request.Cookies;
            HttpCookie           cookie          = cookies[".AspNet.ApplicationCookie"];

            cookieContainer.Add(new Cookie(cookie.Name, cookie.Value, cookie.Path, _context.Request.Url.Host));
            HttpClientHandler httpClientHandler = new HttpClientHandler {
                UseCookies = true, CookieContainer = cookieContainer
            };
            HttpClient httpClient = new HttpClient(httpClientHandler);
            string     url        = _urlHelper.Action("ExecuteNext", "BatchExecution", new { id = run.Guid }, "http");

            httpClient.GetAsync(url);
        }
Ejemplo n.º 18
0
//Obtain profit mean
        public static void GetBatchRunProfitMean(BatchRun batchRun)
        {
            string connStr  = ConfigurationManager.AppSettings["connStr"];
            string sCommand = "GetProfitMean";

            using (SqlConnection sConnect = new SqlConnection(connStr))
            {
                using (SqlCommand sqlCommand = new SqlCommand(sCommand, sConnect))
                {
                    sqlCommand.CommandType = CommandType.StoredProcedure;

                    sqlCommand.Parameters.Add("@BatchRunId", SqlDbType.Int).Value = batchRun.BatchRunId;

                    sConnect.Open();
                    sqlCommand.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 19
0
 public bool Start(BatchRun batchRun)
 {
     batchRun = GetBatchRunFromThisSession(batchRun);
     if (batchRun == null ||
         (batchRun.Status == BatchRunStatus.Executing || batchRun.Status == BatchRunStatus.Complete))
     {
         return(false);
     }
     _session.Transact(session =>
     {
         batchRun.Status = BatchRunStatus.Executing;
         session.Update(batchRun);
     });
     EventContext.Instance.Publish <IOnBatchRunStart, BatchRunStartArgs>(new BatchRunStartArgs
     {
         BatchRun = batchRun
     });
     return(true);
 }
Ejemplo n.º 20
0
 public bool Pause(BatchRun batchRun)
 {
     batchRun = GetBatchRunFromThisSession(batchRun);
     if (batchRun == null ||
         (batchRun.Status != BatchRunStatus.Executing))
     {
         return(false);
     }
     _session.Transact(session =>
     {
         batchRun.Status = BatchRunStatus.Paused;
         session.Update(batchRun);
     });
     EventContext.Instance.Publish <IOnBatchRunPause, BatchRunPauseArgs>(new BatchRunPauseArgs
     {
         BatchRun = batchRun
     });
     return(true);
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Adds the runs from the optimizerTask to the batchrun and replaces the Optimizer
        /// Sideeffect: the optimizerTask.Optimizer will be prepared (scopes are deleted and executionstate will be reset)
        /// </summary>
        private void UpdateOptimizerInBatchRun(BatchRun batchRun, OptimizerTask optimizerTask)
        {
            itemTaskLock.EnterWriteLock();
            try {
                if (optimizerTask.Item is IAlgorithm)
                {
                    // only set the first optimizer as Optimizer. if every time the Optimizer would be set, the runs would be cleared each time
                    if (batchRun.Optimizer == null)
                    {
                        batchRun.Optimizer = (IOptimizer)optimizerTask.Item.Clone();
                        batchRun.Optimizer.Runs.Clear();
                    }

                    foreach (IRun run in optimizerTask.Item.Runs)
                    {
                        run.Name = GetNewRunName(run, batchRun.Runs);
                        batchRun.Optimizer.Runs.Add(run);
                    }
                }
                else
                {
                    // only set the first optimizer as Optimizer. if every time the Optimizer would be set, the runs would be cleared each time
                    if (batchRun.Optimizer == null)
                    {
                        batchRun.Optimizer = optimizerTask.Item;
                    }
                    foreach (IRun run in optimizerTask.Item.Runs)
                    {
                        if (batchRun.Runs.Contains(run))
                        {
                            continue;
                        }
                        run.Name = GetNewRunName(run, batchRun.Runs);
                        batchRun.Runs.Add(run);
                    }
                }
            }
            finally {
                itemTaskLock.ExitWriteLock();
            }
        }
Ejemplo n.º 22
0
        public static void InsertOneBatchRun(BatchRun batchRun)
        {
            string        connStr = ConfigurationManager.AppSettings["connStr"];
            StringBuilder sb      = new StringBuilder("Insert into BatchRun(BatchRunId,CreateDate,Path,ProfitMean) values(");

            sb.Append(batchRun.BatchRunId);
            sb.Append(",'");
            sb.Append(batchRun.CreateDate);
            sb.Append("',");
            sb.Append(batchRun.Path);
            sb.Append(",");
            sb.Append(batchRun.ProfitMean);
            sb.Append(")");

            using (SqlConnection sConnect = new SqlConnection(connStr))
            {
                using (SqlCommand sCommand = new SqlCommand(sb.ToString(), sConnect))
                {
                    sConnect.Open();
                    sCommand.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 23
0
 public void Paused(BatchRun batchRun)
 {
     SetStatus(batchRun, BatchRunStatus.Paused);
 }
Ejemplo n.º 24
0
 public void Complete(BatchRun batchRun)
 {
     SetStatus(batchRun, BatchRunStatus.Complete);
 }
Ejemplo n.º 25
0
 public void BatchRunConstructorTest()
 {
     string batch_directory_passed = string.Empty; // TODO: Initialize to an appropriate value
     BatchRun target = new BatchRun(batch_directory_passed);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Ejemplo n.º 26
0
 public void ExecuteRequestForNextTask(BatchRun run)
 {
     _executeRequestForNextTask.Execute(run);
 }
Ejemplo n.º 27
0
 public bool Pause(BatchRun run)
 {
     return(_controlBatchRun.Pause(run));
 }
Ejemplo n.º 28
0
 public int?Start(BatchRun run)
 {
     return(_controlBatchRun.Start(run) ? run.Id : (int?)null);
 }
Ejemplo n.º 29
0
 public async Task <int?> ExecuteNextTask(BatchRun run)
 {
     return(await _executeNextBatchJob.Execute(run) ? run.Id : (int?)null);
 }
Ejemplo n.º 30
0
 public JsonResult ExecuteNext(BatchRun run)
 {
     return(Json(_batchRunUIService.ExecuteNextTask(run)));
 }
Ejemplo n.º 31
0
 public ActionResult Row(BatchRun batchRun)
 {
     ViewData["completion-status"] = _batchRunUIService.GetCompletionStatus(batchRun);
     return(PartialView(batchRun));
 }