Skip to content

Commit 578ae14

Browse files
committed
global running task_id
1 parent f9b2a6d commit 578ae14

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

examples/server/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ std::queue<std::function<void()>> task_queue;
837837
std::mutex queue_mutex;
838838
std::condition_variable queue_cond;
839839
bool stop_worker = false;
840-
std::atomic<bool> is_task_running(false);
840+
std::atomic<bool> is_busy(false);
841+
std::string running_task_id("");
841842

842843
std::unordered_map<std::string, nlohmann::json> task_results;
843844
std::mutex results_mutex;
@@ -848,12 +849,12 @@ void worker_thread() {
848849
queue_cond.wait(lock, [] { return !task_queue.empty() || stop_worker; });
849850

850851
if (!task_queue.empty()) {
851-
is_task_running = true;
852+
is_busy = true;
852853
auto task = task_queue.front();
853854
task_queue.pop();
854855
lock.unlock();
855856
task();
856-
is_task_running = false;
857+
is_busy = false;
857858
}
858859
}
859860
}
@@ -935,6 +936,7 @@ void start_server(SDParams params) {
935936
task_results[task_id] = pending_task_json;
936937

937938
auto task = [&req, &sd_ctx, &params, &n_prompts, task_id]() {
939+
running_task_id = task_id;
938940
// LOG_DEBUG("raw body is: %s\n", req.body.c_str());
939941
sd_log(sd_log_level_t::SD_LOG_DEBUG, "raw body is: %s\n", req.body.c_str());
940942
// parse req.body as json using jsoncpp

0 commit comments

Comments
 (0)