From 37f595ed9a19863bbef697cc14c179e843abdd99 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 11 Feb 2019 09:55:18 -0500 Subject: [PATCH] Add startup delay for security discovery --- src/lib/config/defaults/MarketData.conf | 13 +++++++++++++ src/lib/config/protos/MarketData.proto | 11 +++++++++++ src/lib/utils/datetime.cpp | 21 +++++++++++++++++++++ src/lib/utils/datetime.h | 4 ++++ src/server/sparkd/md/run_md.cpp | 24 ++++++++++++++++++++++-- 5 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/lib/config/defaults/MarketData.conf b/src/lib/config/defaults/MarketData.conf index 17d800d6b..0a11b62c6 100644 --- a/src/lib/config/defaults/MarketData.conf +++ b/src/lib/config/defaults/MarketData.conf @@ -35,3 +35,16 @@ CMEOptions { } } +MDBootDelayWindow { + value { + delay_seconds: 120 + standard { + start: "16:30" + end: "16:40" + } + sunday { + start: "14:00" + end: "14:10" + } + } +} \ No newline at end of file diff --git a/src/lib/config/protos/MarketData.proto b/src/lib/config/protos/MarketData.proto index 08b397958..aba6237c6 100755 --- a/src/lib/config/protos/MarketData.proto +++ b/src/lib/config/protos/MarketData.proto @@ -15,6 +15,17 @@ message PlatformMap optional string glbx_platform = 1 [default = "PLATFORM_SIM"]; } +// LOCAL TIME +message MDBootDelayWindow { + message TimeSpan { + optional string start = 1 [default = "16:30"]; + optional string end = 2 [default = "16:40"]; + } + optional uint32 delay_seconds = 1 [default = 120]; + optional TimeSpan standard = 2; + optional TimeSpan sunday = 3; +} + // // Options that apply to market data server diff --git a/src/lib/utils/datetime.cpp b/src/lib/utils/datetime.cpp index 5e776e159..4cd7fe092 100755 --- a/src/lib/utils/datetime.cpp +++ b/src/lib/utils/datetime.cpp @@ -1,5 +1,6 @@ #include "datetime.h" + #include "bts_assert.h" #include "TimeStamp.h" @@ -317,6 +318,26 @@ Date ll_to_date(LLDateTime time) { return date; } + +bool is_local_time_sunday() { + auto now = local_now(); + return now.date().day_of_week() == boost::date_time::Sunday; +} +bool is_local_time_between(int hh_start, int mm_start, int hh_end, int mm_end) { + auto now = local_now(); + auto hh_now = now.time_of_day().hours(); + auto mm_now = now.time_of_day().minutes(); + + if (hh_now > hh_start && hh_now < hh_end) return true; + if (hh_now == hh_start || hh_now == hh_end) { + if (mm_now >= mm_start && mm_now <= mm_end) { + return true; + } + } + return false; +} + + struct UtcTimeStamp { int hour; int min; diff --git a/src/lib/utils/datetime.h b/src/lib/utils/datetime.h index e6095ad82..133555edc 100755 --- a/src/lib/utils/datetime.h +++ b/src/lib/utils/datetime.h @@ -76,11 +76,15 @@ BTS_EXPORT bool is_at_least_days_old (PTime const &time, uint64_t days); BTS_EXPORT LLDateTime ll_from_unix_epoch(long); BTS_EXPORT LLDateTime ll_from_unix_epoch_ms(long long); + extern "C" BTS_EXPORT void ll_to_parts(LLDateTime, int& year, int& month, int& day, int& hour, int& minute, int& second, int& millisecond); BTS_EXPORT Date ll_to_date(LLDateTime); extern "C" BTS_EXPORT LLDateTime ll_from_parts(int year, int month, int day, int hour, int minute, int second, int millisecond); BTS_EXPORT LLDateTime ll_from_date(const Date& date); +bool is_local_time_sunday(); +bool is_local_time_between(int hh_start, int mm_start, int hh_end, int mm_end); + #ifndef NO_CPP0X extern "C" BTS_EXPORT LLDateTime ll_today(); BTS_EXPORT Date today(); diff --git a/src/server/sparkd/md/run_md.cpp b/src/server/sparkd/md/run_md.cpp index 6bb2a2ef5..56e2c2762 100644 --- a/src/server/sparkd/md/run_md.cpp +++ b/src/server/sparkd/md/run_md.cpp @@ -90,6 +90,26 @@ void run_market_data_publishers_forever() { } } +void boot_sleep() { + auto conf = config::get(); + const auto* schedule = &conf.standard(); + if (datetime::is_local_time_sunday()) { + schedule = &conf.sunday(); + } + bts_assert(schedule); + int hh_start = 0, mm_start = 0, hh_end = 0, mm_end = 0; + sscanf(schedule->start().c_str(), "%i:%i", &hh_start, &mm_start); + sscanf(schedule->end().c_str(), "%i:%i", &hh_end, &mm_end); + if (datetime::is_local_time_between(hh_start, mm_start, hh_end, mm_end)) { + std::this_thread::sleep_for( + std::chrono::seconds( + conf.delay_seconds())); + } + else { + std::this_thread::sleep_for(2s); + } +} + void run_market_datapublishers() { bts_assert(_md_thread == nullptr); run_cleanup(); @@ -103,10 +123,10 @@ void run_market_datapublishers() { threading::make_thread("ExchangeSim", []() { sim::start_exchange_sim(); }) .detach(); } - - std::this_thread::sleep_for(2s); + boot_sleep(); } + void run_record(const std::string& arg){ boost::filesystem::path p(arg); record_everything(p.parent_path().string(), p.filename().string());