Skip to content

Commit e97d0fa

Browse files
committed
Hub optimization
1 parent 504ed5a commit e97d0fa

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/tasks/hub_task.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ use crate::epsilon::server::templates::template::Template;
66
use crate::{EResult, EpsilonApi, InstanceProvider, Task};
77
use async_trait::async_trait;
88
use std::sync::Arc;
9+
use std::time::Duration;
910
use tokio::sync::Mutex;
1011

12+
const DEFAULT_TIME: &'static u32 = &60;
13+
1114
pub struct HubTask {
1215
instance_provider: Arc<InstanceProvider>,
1316
hub_template: Template,
17+
18+
time: u32,
1419
}
1520

1621
#[async_trait]
@@ -23,6 +28,8 @@ impl Task for HubTask {
2328
Ok(Box::new(Self {
2429
instance_provider: Arc::clone(instance_provider),
2530
hub_template: instance_provider.get_template("hub").await?,
31+
32+
time: 0,
2633
}))
2734
}
2835

@@ -37,15 +44,26 @@ impl Task for HubTask {
3744
let proxy_number = proxies.len();
3845

3946
if proxy_number > 0 {
40-
let hubs = self
47+
let hubs_starting = self
4148
.instance_provider
42-
.get_instances(&InstanceType::Server, Some(template_name), None)
49+
.get_instances(
50+
&InstanceType::Server,
51+
Some(template_name),
52+
Some(&EpsilonState::Starting),
53+
)
4354
.await?;
4455

45-
let hub_online_count_result = hubs.get_online_count().await;
56+
let hubs_ready = self
57+
.instance_provider
58+
.get_instances(
59+
&InstanceType::Server,
60+
Some(template_name),
61+
Some(&EpsilonState::Running),
62+
)
63+
.await?;
4664

47-
if let Ok(hub_online_count) = hub_online_count_result {
48-
let hub_number = hubs.len() as u32;
65+
if let Ok(hub_online_count) = hubs_ready.get_online_count().await {
66+
let hub_number = hubs_ready.len() as u32;
4967

5068
let hub_necessary =
5169
((hub_online_count as f32 * 1.6 / self.hub_template.slots as f32) + 1.0) as u32;
@@ -55,10 +73,18 @@ impl Task for HubTask {
5573
}
5674

5775
if hub_number > hub_necessary {
76+
if self.time != *DEFAULT_TIME {
77+
self.time += 1;
78+
79+
return Ok(());
80+
} else {
81+
self.time = 0;
82+
}
83+
5884
let mut n = 0;
5985
let mut hub_option = None;
6086

61-
for instance in hubs {
87+
for instance in hubs_ready {
6288
let info_result = instance.get_info().await;
6389

6490
if let Ok(info) = info_result {

0 commit comments

Comments
 (0)