Skip to content

Commit

Permalink
More logging in the beekeeper application
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz-Trela authored and vogel76 committed Apr 24, 2024
1 parent ae5ed7c commit dcfaeff
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
16 changes: 12 additions & 4 deletions libraries/appbase/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,11 @@ void application::wait4interrupt_request()
}
}

void application::wait()
void application::wait( bool log )
{
if( log ) ilog("Wait for interrupt request");
wait4interrupt_request();
if( log ) ilog("Interrupt request has been generated");

if( finish_request )
{
Expand All @@ -426,9 +428,11 @@ void application::wait()
ilog("Request for application shutdown processed.");
}

if( log ) ilog("Wait for finishing plugins");
finish();
if( log ) ilog("Plugins have been finished");

handler_wrapper.wait4stop();
handler_wrapper.wait4stop( log );
}

bool application::is_thread_closed()
Expand Down Expand Up @@ -646,13 +650,17 @@ void application::kill( bool direct_stop )
::kill(getpid(), SIGINT);
}

bool application::quit()
bool application::quit( bool log )
{
auto _is_thread_closed = is_thread_closed();
if( !_is_thread_closed )
{
if( log ) ilog("Kill application");
kill();
if( log ) ilog("Application has been killed");
}

wait();
wait( log );

return is_thread_closed();
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/appbase/include/appbase/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace appbase {
* Wait until quit(), SIGINT or SIGTERM and then shutdown
*/
void wait4interrupt_request();
void wait();
void wait( bool log = false );
bool is_thread_closed();

template< typename Plugin >
Expand Down Expand Up @@ -167,7 +167,7 @@ namespace appbase {
std::set< std::string > get_plugins_names() const;

void kill( bool direct_stop = false ); // direct_stop is only viable for unit tests where signals don't work
bool quit();
bool quit( bool log = false );

using finish_request_type = std::function<void()>;

Expand Down
2 changes: 1 addition & 1 deletion libraries/appbase/include/appbase/signals_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace appbase {
signals_handler_wrapper( signals_handler::interrupt_request_generation_type&& _interrupt_request_generation );

void init();
void wait4stop();
void wait4stop( bool log = false );
void force_stop();
bool is_thread_closed();

Expand Down
9 changes: 8 additions & 1 deletion libraries/appbase/signals_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,23 @@ void signals_handler_wrapper::init()
initialized = true;
}

void signals_handler_wrapper::wait4stop()
void signals_handler_wrapper::wait4stop( bool log )
{
if( initialized )
{
if( handler_thread->joinable() )
{
if( log ) ilog("Clearing signals");
handler.clear_signals();
if( log ) ilog("Signals have been cleared");

if( log ) ilog("Stopping IO service");
get_io_service().stop();
if( log ) ilog("IO service has been stopped");

if( log ) ilog("Joining handler's thread");
handler_thread->join();
if( log ) ilog("Handler's thread has been joined");
}
}
thread_closed = true;
Expand Down
12 changes: 10 additions & 2 deletions programs/beekeeper/beekeeper/beekeeper_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ beekeeper_app::beekeeper_app()

beekeeper_app::~beekeeper_app()
{
if( app.quit() && start_loop )
if( start_loop )
{
ilog("beekeeper is exiting");
app.quit( true/*log*/ );
ilog("exited cleanly");
}
else
app.quit();
}

void beekeeper_app::set_program_options()
Expand Down Expand Up @@ -188,7 +194,9 @@ void beekeeper_app::start()

app.notify_status( "beekeeper is ready" );

app.wait();
ilog("beekeeper is waiting");
app.wait( true/*log*/ );
ilog("waiting is finished");
}

const boost::program_options::variables_map& beekeeper_app::get_args() const
Expand Down

0 comments on commit dcfaeff

Please sign in to comment.