예제 #1
0
파일: Startup.cs 프로젝트: Tiller431/yes
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              Crawler crawler, APIAccess apiv2, Kaesereibe reibe, BeatmapSearchEngine searchEngine, BMUpdater bmUpdater)
        {
            if (Environment.GetEnvironmentVariable("LOG_LEVEL") != null)
            {
                if (Enum.TryParse(Environment.GetEnvironmentVariable("LOG_LEVEL"), out LogLevel level))
                {
                    Logger.Level = level;
                }
            }

            Logger.Storage = dataStorage.GetStorageForDirectory("logs");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            if (searchEngine.Search("test") == null)
            {
                Logger.LogPrint("Failed to Connect to ElasticSearch!", LoggingTarget.Network, LogLevel.Error);
                Environment.Exit(0);
            }

            apiv2.Login(Environment.GetEnvironmentVariable("OSU_EMAIL"), Environment.GetEnvironmentVariable("OSU_PASSWORD"));

            DogStatsd.Configure(new StatsdConfig {
                Prefix = "pisstaube"
            });

            DogStatsd.ServiceCheck("crawler.is_crawling", Status.UNKNOWN);

            if (Environment.GetEnvironmentVariable("CRAWLER_DISABLED") != "true")
            {
                crawler.BeginCrawling();
            }
            else
            {
                DogStatsd.ServiceCheck("crawler.is_crawling", Status.CRITICAL);
            }

            if (Environment.GetEnvironmentVariable("CHEESEGULL_CRAWLER_DISABLED") != "true")
            {
                reibe.BeginCrawling();
            }
            else
            {
                DogStatsd.ServiceCheck("kaesereibe.is_crawling", Status.CRITICAL);
            }

            if (!Directory.Exists("data"))
            {
                Directory.CreateDirectory("data");
            }

            if (!Directory.Exists("data/cache"))
            {
                Directory.CreateDirectory("data/cache");
            }

            DogStatsd.ServiceCheck("is_active", Status.OK);

            if (Environment.GetEnvironmentVariable("UPDATER_DISABLED") != "true")
            {
                bmUpdater.BeginUpdaterAsync();
            }

            app.UseMvc(routes => routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"));
        }
예제 #2
0
        public ActionResult Recovery(
            [FromQuery] string key,
            [FromQuery] RecoveryAction action
            )
        {
            if (key != Environment.GetEnvironmentVariable("PRIVATE_API_KEY"))
            {
                return(Unauthorized("Key is wrong!"));
            }

            switch (action)
            {
            case RecoveryAction.RepairElastic:
                Logger.LogPrint("Repairing ElasticSearch");
                _crawler.Stop();
                _reibe.Stop();

                _searchEngine.DeleteAllBeatmaps();

                foreach (var beatmapSet in _contextFactory.Get().BeatmapSet)
                {
                    beatmapSet.ChildrenBeatmaps = _contextFactory.Get().Beatmaps.Where(b => b.ParentSetId == beatmapSet.SetId).ToList();
                    _searchEngine.IndexBeatmap(beatmapSet);
                }

                if (Environment.GetEnvironmentVariable("CRAWLER_DISABLED") != "true")
                {
                    _crawler.BeginCrawling();
                }

                if (Environment.GetEnvironmentVariable("CHEESEGULL_CRAWLER_DISABLED") != "true")
                {
                    _reibe.BeginCrawling();
                }
                break;

            case RecoveryAction.RecrawlEverything:
                Logger.LogPrint("Recrawl Everything!");

                _crawler.Stop();
                _reibe.Stop();

                _searchEngine.DeleteAllBeatmaps();
                using (var db = _contextFactory.GetForWrite()) {
                    db.Context.Database.ExecuteSqlCommand("SET FOREIGN_KEY_CHECKS = 0;" +
                                                          "TRUNCATE TABLE `Beatmaps`;" +
                                                          "ALTER TABLE `Beatmaps` AUTO_INCREMENT = 1;" +
                                                          "TRUNCATE TABLE `BeatmapSet`;" +
                                                          "ALTER TABLE `BeatmapSet` AUTO_INCREMENT = 1;" +
                                                          "SET FOREIGN_KEY_CHECKS = 1;");
                }
                using (var cacheDb = _cache.GetForWrite())
                {
                    cacheDb.Context.Database.ExecuteSqlCommand(
                        "DELETE FROM `CacheBeatmaps`;" +
                        "DELETE FROM `CacheBeatmapSet`;");
                }
                if (Environment.GetEnvironmentVariable("CRAWLER_DISABLED") != "true")
                {
                    _crawler.BeginCrawling();
                }
                if (Environment.GetEnvironmentVariable("CHEESEGULL_CRAWLER_DISABLED") != "true")
                {
                    _reibe.BeginCrawling();
                }
                break;

            case RecoveryAction.RecrawlUnknown:
                Logger.LogPrint("Recrawl All unknown maps!");

                _crawler.Stop();
                using (var db = _contextFactory.GetForWrite()) {
                    for (var i = 0; i < db.Context.BeatmapSet.Last().SetId; i++)
                    {
                        if (!db.Context.BeatmapSet.Any(set => set.SetId == i))
                        {
                            _crawler.Crawl(i, db.Context);
                        }
                    }
                }
                _crawler.BeginCrawling();
                break;

            default:
                return(BadRequest("Unknown Action type!"));
            }

            return(Ok("Success!"));
        }