1 /* $Id: cass_monitor.cpp 618178 2020-10-13 17:12:58Z satskyse $ 2 * =========================================================================== 3 * 4 * PUBLIC DOMAIN NOTICE 5 * National Center for Biotechnology Information 6 * 7 * This software/database is a "United States Government Work" under the 8 * terms of the United States Copyright Act. It was written as part of 9 * the author's official duties as a United States Government employee and 10 * thus cannot be copyrighted. This software/database is freely available 11 * to the public for use. The National Library of Medicine and the U.S. 12 * Government have not placed any restriction on its use or reproduction. 13 * 14 * Although all reasonable efforts have been taken to ensure the accuracy 15 * and reliability of the software and data, the NLM and the U.S. 16 * Government do not and cannot warrant the performance or results that 17 * may be obtained by using this software or data. The NLM and the U.S. 18 * Government disclaim all warranties, express or implied, including 19 * warranties of performance, merchantability or fitness for any particular 20 * purpose. 21 * 22 * Please cite the author in any work or product based on this material. 23 * 24 * =========================================================================== 25 * 26 * Authors: Sergey Satskiy 27 * 28 * File Description: PSG server Cassandra monitoring 29 * 30 */ 31 #include <ncbi_pch.hpp> 32 #include <corelib/ncbistd.hpp> 33 #include <thread> 34 #include <chrono> 35 36 #include "cass_monitor.hpp" 37 #include "pubseq_gateway.hpp" 38 39 #include "shutdown_data.hpp" 40 extern SShutdownData g_ShutdownData; 41 CassMonitorThreadedFunction(void)42void CassMonitorThreadedFunction(void) 43 { 44 auto app = CPubseqGatewayApp::GetInstance(); 45 46 for ( ; ; ) { 47 // The thread should wake up once per minute 48 std::this_thread::sleep_for(std::chrono::seconds(60)); 49 50 if (g_ShutdownData.m_ShutdownRequested) 51 break; 52 53 switch (app->GetStartupDataState()) { 54 case ePSGS_NoCassConnection: 55 if (app->OpenCass()) { 56 // Public comments mapping (populated once) 57 app->PopulatePublicCommentsMapping(); 58 59 // true => the 'accept' alert is set if sucessfull 60 if (app->PopulateCassandraMapping(true)) { 61 app->OpenCache(); 62 } 63 } 64 break; 65 case ePSGS_NoValidCassMapping: 66 // true => the 'accept' alert is set if sucessfull 67 if (app->PopulateCassandraMapping(true)) 68 app->OpenCache(); 69 break; 70 case ePSGS_NoCassCache: 71 app->OpenCache(); 72 break; 73 case ePSGS_StartupDataOK: 74 app->CheckCassMapping(); 75 break; 76 } 77 } 78 } 79 80