server: Return shutdown_handler to its initial state and use running = false for termination
This commit is contained in:
parent
a4108f59bd
commit
acbac00f0d
1 changed files with 4 additions and 14 deletions
|
@ -1164,16 +1164,6 @@ struct server_metrics {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct termination_signal {
|
|
||||||
int number;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct standby_timeout {};
|
|
||||||
|
|
||||||
using shutdown_reason = std::variant<termination_signal, standby_timeout>;
|
|
||||||
|
|
||||||
std::function<void(shutdown_reason)> shutdown_handler;
|
|
||||||
|
|
||||||
struct server_queue {
|
struct server_queue {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
bool running;
|
bool running;
|
||||||
|
@ -1308,9 +1298,8 @@ struct server_queue {
|
||||||
};
|
};
|
||||||
if (standby_timeout > 0) {
|
if (standby_timeout > 0) {
|
||||||
if (!condition_tasks.wait_for(lock, std::chrono::seconds(standby_timeout), pred)) {
|
if (!condition_tasks.wait_for(lock, std::chrono::seconds(standby_timeout), pred)) {
|
||||||
lock.release()->unlock(); // unlock the unique_lock, before calling the shutdown_handler, as it tries to lock it
|
|
||||||
QUE_INF("%s", "stand-by timeout reached\n");
|
QUE_INF("%s", "stand-by timeout reached\n");
|
||||||
shutdown_handler(::standby_timeout{});
|
running = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2906,6 +2895,7 @@ static void log_server_request(const httplib::Request & req, const httplib::Resp
|
||||||
LOG_DBG("response: %s\n", res.body.c_str());
|
LOG_DBG("response: %s\n", res.body.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::function<void(int)> shutdown_handler;
|
||||||
std::atomic_flag is_terminating = ATOMIC_FLAG_INIT;
|
std::atomic_flag is_terminating = ATOMIC_FLAG_INIT;
|
||||||
|
|
||||||
inline void signal_handler(int signal) {
|
inline void signal_handler(int signal) {
|
||||||
|
@ -2916,7 +2906,7 @@ inline void signal_handler(int signal) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown_handler(termination_signal{ signal });
|
shutdown_handler(signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
|
@ -3956,7 +3946,7 @@ int main(int argc, char ** argv) {
|
||||||
ctx_server.queue_tasks.on_update_slots(std::bind(
|
ctx_server.queue_tasks.on_update_slots(std::bind(
|
||||||
&server_context::update_slots, &ctx_server));
|
&server_context::update_slots, &ctx_server));
|
||||||
|
|
||||||
shutdown_handler = [&](shutdown_reason) {
|
shutdown_handler = [&](int) {
|
||||||
ctx_server.queue_tasks.terminate();
|
ctx_server.queue_tasks.terminate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue