public void Start() { Database.Initialize(ConnectionString); DapperConfig.Initialize(); DefaultTraceLogInitializer.Initialize(ConnectionString, TraceLogLevel.Trace); MarkdownParser.RegisterJsEngineType<V8JsEngine>(); _logger.Trace(string.Format("WEBJOB Start: Interval = {0} ミリ秒", Interval.ToString("##,###"))); var service = new SearchService(ConnectionString); var status = service.GetServiceStatusAsync().Result; if (status == ServiceStatus.IndexNotExists) { service.RecreateEsIndexAsync().Wait(); } _timer = new Timer { Interval = Interval }; _timer.Elapsed += Execute; _timer.Start(); }
private static void Execute(object sender, EventArgs e) { var logger = LogManager.GetTraceLogger("WEBJOB"); logger.Trace(new TraceLogMessage(new {Command = "Execution Start"}, "Elasticsearch")); var sw = Stopwatch.StartNew(); var indexedItemCount = 0; try { var itemDbCommand = new ItemDbCommand(ConnectionString); var notIndexedItems = itemDbCommand.GetNotIndexedItemsAsync().Result; indexedItemCount = notIndexedItems.Count(); var searchSearvice = new SearchService(ConnectionString); searchSearvice.BulkItemsAsync(notIndexedItems).Wait(); } catch (Exception exception) { logger.Error(exception); } sw.Stop(); logger.Trace( new TraceLogMessage( new { itemDbCommand = "Execution End", IndexedItemCount = indexedItemCount }, "Elasticsearch", sw.ElapsedMilliseconds)); }