Ejemplo n.º 1
0
        public override async Task InitializeAsync(IVostokHostingEnvironment environment)
        {
            await base.InitializeAsync(environment);

            keepAliver        = new ServiceKeepAliver(configuration.GraphiteServiceName);
            keepAliveInterval = TimeSpan.FromSeconds(configuration.KeepAliveInterval ?? 30);
        }
Ejemplo n.º 2
0
        public Program(WebCourseManager courseManager)
        {
            this.courseManager = courseManager;
            notificationSender = new NotificationSender(courseManager);
            var configuration = ApplicationConfiguration.Read <UlearnConfiguration>();

            keepAliver        = new ServiceKeepAliver(configuration.GraphiteServiceName);
            keepAliveInterval = TimeSpan.FromSeconds(configuration.KeepAliveInterval ?? 30);
        }
Ejemplo n.º 3
0
        public Program(WebCourseManager courseManager)
        {
            this.courseManager = courseManager;
            notificationSender = new NotificationSender(courseManager);
            keepAliver         = new ServiceKeepAliver("notifications");

            if (!int.TryParse(ConfigurationManager.AppSettings["ulearn.notifications.keepAlive.interval"], out var keepAliveIntervalSeconds))
            {
                keepAliveIntervalSeconds = 30;
            }
            keepAliveInterval = TimeSpan.FromSeconds(keepAliveIntervalSeconds);
        }
Ejemplo n.º 4
0
        private void MainLoop(Client client)
        {
            var serviceKeepAliver = new ServiceKeepAliver(serviceName);
            var configuration     = ApplicationConfiguration.Read <UlearnConfiguration>();
            var keepAliveInterval = TimeSpan.FromSeconds(configuration.KeepAliveInterval ?? 30);

            while (!shutdownEvent.WaitOne(0))
            {
                var unhandledSubmissions = new List <RunnerSubmission>();
                try
                {
                    unhandledSubmissions.AddRange(client.TryGetSubmission(supportedSandboxes).Result);
                }
                catch (Exception e)
                {
                    log.Error(e, $"Не могу получить решения из ulearn. Следующая попытка через {sleep.TotalSeconds} секунд");
                    Thread.Sleep(sleep);
                    continue;
                }

                log.Info($"Получил {unhandledSubmissions.Count} решение(й) со следующими ID: [{string.Join(", ", unhandledSubmissions.Select(s => s.Id))}]");

                foreach (var submission in unhandledSubmissions)
                {
                    RunningResults result;
                    try
                    {
                        result = SandboxRunnerClient.Run(submission);
                        log.Info($"Результат проверки: [{result}]");
                    }
                    catch (Exception ex)
                    {
                        result = new RunningResults(submission.Id, Verdict.SandboxError, error: ex.ToString());
                        log.Error(ex);
                    }

                    try
                    {
                        client.SendResults(result);
                    }
                    catch (Exception e)
                    {
                        log.Error(e, "Не могу отправить результаты проверки на ulearn");
                    }
                }

                serviceKeepAliver.Ping(keepAliveInterval);
                Thread.Sleep(sleep);
            }
        }
Ejemplo n.º 5
0
        private void MainLoop(Client client)
        {
            var serviceKeepAliver = new ServiceKeepAliver(serviceName);
            var configuration     = ApplicationConfiguration.Read <UlearnConfiguration>();
            var keepAliveInterval = TimeSpan.FromSeconds(configuration.KeepAliveInterval ?? 30);

            while (!shutdownEvent.WaitOne(0))
            {
                var newUnhandled = new List <RunnerSubmission>();
                try
                {
                    newUnhandled.AddRange(client.TryGetSubmission(supportedLanguages).Result);
                }
                catch (Exception e)
                {
                    log.Error($"Не могу получить решения из ulearn. Следующая попытка через {sleep.TotalSeconds} секунд", e);
                    Thread.Sleep(sleep);
                    continue;
                }

                log.Info($"Получил {newUnhandled.Count} решение(й) со следующими ID: [{string.Join(", ", newUnhandled.Select(s => s.Id))}]");

                if (newUnhandled.Any())
                {
                    var results = newUnhandled.Select(unhandled => SandboxRunnerClient.Run(unhandled)).ToList();
                    log.Info($"Результаты проверки: [{string.Join(", ", results.Select(r => r.Verdict))}]");
                    try
                    {
                        client.SendResults(results);
                    }
                    catch (Exception e)
                    {
                        log.Error("Не могу отправить результаты проверки на ulearn", e);
                    }
                }

                serviceKeepAliver.Ping(keepAliveInterval);
                Thread.Sleep(sleep);
            }
        }
Ejemplo n.º 6
0
        private void MainLoop(Client client)
        {
            var serviceKeepAliver = new ServiceKeepAliver("runcsjob");

            while (!shutdownEvent.WaitOne(0))
            {
                List <RunnerSubmission> newUnhandled;
                try
                {
                    newUnhandled = client.TryGetSubmission().Result;
                }
                catch (Exception e)
                {
                    log.Error($"Не могу получить решения из ulearn. Следующая попытка через {sleep.TotalSeconds} секунд", e);
                    Thread.Sleep(sleep);
                    continue;
                }

                log.Info($"Получил {newUnhandled.Count} решение(й) со следующими ID: [{string.Join(", ", newUnhandled.Select(s => s.Id))}]");

                if (newUnhandled.Any())
                {
                    var results = newUnhandled.Select(unhandled => SandboxRunner.Run(unhandled, Settings)).ToList();
                    log.Info($"Результаты проверки: [{string.Join(", ", results.Select(r => r.Verdict))}]");
                    try
                    {
                        client.SendResults(results);
                    }
                    catch (Exception e)
                    {
                        log.Error("Не могу отправить результаты проверки на ulearn", e);
                    }
                }
                serviceKeepAliver.Ping(TimeSpan.FromMinutes(1));
                Thread.Sleep(sleep);
            }
        }