|
1 | 1 | use std::future::Future; |
2 | 2 | use std::rc::Rc; |
3 | 3 | use std::sync::Arc; |
4 | | -use std::time::Duration; |
| 4 | +use std::time::{Duration, Instant}; |
5 | 5 |
|
6 | 6 | use orion::aead::SecretKey; |
7 | 7 | use tokio::net::TcpListener; |
8 | | -use tokio::sync::{Notify, oneshot}; |
| 8 | +use tokio::sync::Notify; |
9 | 9 |
|
10 | 10 | use crate::events::EventProcessor; |
11 | 11 | use crate::gateway::{MultiNodeAllocationResponse, TaskSubmit, WorkerRuntimeInfo}; |
12 | 12 | use crate::internal::messages::worker::ToWorkerMessage; |
13 | 13 | use crate::internal::scheduler::query::compute_new_worker_query; |
14 | | -use crate::internal::scheduler::state::scheduler_loop; |
| 14 | +use crate::internal::scheduler::state::{run_scheduling_now, scheduler_loop}; |
15 | 15 | use crate::internal::server::client::handle_new_tasks; |
16 | 16 | use crate::internal::server::comm::{Comm, CommSenderRef}; |
17 | 17 | use crate::internal::server::core::{CoreRef, CustomConnectionHandler}; |
@@ -99,26 +99,24 @@ impl ServerRef { |
99 | 99 | we can get in one allocation at most. |
100 | 100 | This is used for planning multi-node tasks. |
101 | 101 |
|
| 102 | + Note: This call may immediately call the full scheduler procedure. |
| 103 | + This should not bother the user of the call, except it is probably not a good |
| 104 | + idea to call this function often (several times per second) as it may bypass |
| 105 | + a scheduler time limitations. |
102 | 106 | */ |
103 | 107 | pub fn new_worker_query( |
104 | 108 | &self, |
105 | 109 | queries: Vec<WorkerTypeQuery>, |
106 | | - ) -> crate::Result<oneshot::Receiver<NewWorkerAllocationResponse>> { |
| 110 | + ) -> crate::Result<NewWorkerAllocationResponse> { |
107 | 111 | for query in &queries { |
108 | 112 | query.descriptor.validate()?; |
109 | 113 | } |
110 | | - let (sx, rx) = tokio::sync::oneshot::channel(); |
111 | | - if self.comm_ref.get().get_scheduling_flag() { |
112 | | - self.comm_ref |
113 | | - .get_mut() |
114 | | - .add_after_scheduling_callback(Box::new(move |core| { |
115 | | - let _ = sx.send(compute_new_worker_query(core, &queries)); |
116 | | - })); |
117 | | - } else { |
118 | | - let mut core = self.core_ref.get_mut(); |
119 | | - let _ = sx.send(compute_new_worker_query(&mut core, &queries)); |
120 | | - }; |
121 | | - Ok(rx) |
| 114 | + let mut core = self.core_ref.get_mut(); |
| 115 | + let mut comm = self.comm_ref.get_mut(); |
| 116 | + if comm.get_scheduling_flag() { |
| 117 | + run_scheduling_now(&mut core, &mut comm, Instant::now()) |
| 118 | + } |
| 119 | + Ok(compute_new_worker_query(&mut core, &queries)) |
122 | 120 | } |
123 | 121 |
|
124 | 122 | pub fn try_release_memory(&self) { |
|
0 commit comments