-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IS-450 Reload rotation timestamp on each isExitTime request #1757
Changes from 5 commits
e725930
5d8a88d
85c1b31
dd6fdae
f59f486
b3f1c07
573f3c0
1600857
1785847
53ecf1e
9ce9d5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,23 +46,22 @@ void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) { | |
std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() ); | ||
rotationInfoFile << rotationJson; | ||
|
||
m_finishTimestamp = _finishTimestamp; | ||
LOG( m_logger ) << "Set rotation time to " << m_finishTimestamp; | ||
LOG( m_logger ) << "Set rotation time to " << _finishTimestamp; | ||
} | ||
|
||
bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) { | ||
bool InstanceMonitor::isTimeToRotate( uint64_t _blockTimestamp ) const { | ||
if ( !fs::exists( m_rotationInfoFilePath ) ) { | ||
return false; | ||
} | ||
return m_finishTimestamp <= _finishTimestamp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to write information about rotation into logs |
||
return rotationTimestamp() <= _blockTimestamp; | ||
} | ||
|
||
void InstanceMonitor::restoreRotationParams() { | ||
if ( fs::exists( m_rotationInfoFilePath ) ) { | ||
std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); | ||
auto rotationJson = nlohmann::json::parse( rotationInfoFile ); | ||
m_finishTimestamp = rotationJson["timestamp"].get< uint64_t >(); | ||
} | ||
uint64_t InstanceMonitor::rotationTimestamp() const { | ||
std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); | ||
auto rotationJson = nlohmann::json::parse( rotationInfoFile ); | ||
auto timestamp = rotationJson["timestamp"].get< uint64_t >(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add try catch to handle the case of corrupt file |
||
LOG( m_logger ) << "Rotation scheduled for " << timestamp; | ||
return timestamp; | ||
} | ||
|
||
void InstanceMonitor::reportExitTimeReached( bool _reached ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,23 +36,18 @@ class InstanceMonitor { | |
public: | ||
explicit InstanceMonitor( const boost::filesystem::path& _rotationInfoFileDirPath, | ||
std::shared_ptr< StatusAndControl > _statusAndControl = nullptr ) | ||
: m_finishTimestamp( 0 ), | ||
m_rotationInfoFilePath( _rotationInfoFileDirPath / rotation_info_file_name ), | ||
: m_rotationInfoFilePath( _rotationInfoFileDirPath / rotation_info_file_name ), | ||
m_statusAndControl( _statusAndControl ) { | ||
restoreRotationParams(); | ||
reportExitTimeReached( false ); | ||
} | ||
void prepareRotation(); | ||
void initRotationParams( uint64_t _finishTimestamp ); | ||
bool isTimeToRotate( uint64_t _finishTimestamp ); | ||
bool isTimeToRotate( uint64_t _blockTimestamp ) const; | ||
|
||
protected: | ||
void restoreRotationParams(); | ||
[[nodiscard]] uint64_t finishTimestamp() const { return m_finishTimestamp; } | ||
|
||
[[nodiscard]] uint64_t rotationTimestamp() const; | ||
[[nodiscard]] fs::path rotationInfoFilePath() const { return m_rotationInfoFilePath; } | ||
|
||
uint64_t m_finishTimestamp; | ||
const fs::path m_rotationInfoFilePath; | ||
std::shared_ptr< StatusAndControl > m_statusAndControl; | ||
|
||
|
@@ -61,5 +56,5 @@ class InstanceMonitor { | |
void reportExitTimeReached( bool _reached ); | ||
|
||
private: | ||
dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; | ||
mutable dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mutable is not needed here |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add try catch