Skip to content

Commit 2d528db

Browse files
committed
Update hub_task.rs
1 parent e97d0fa commit 2d528db

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

src/tasks/hub_task.rs

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,56 +53,61 @@ impl Task for HubTask {
5353
)
5454
.await?;
5555

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?;
64-
65-
if let Ok(hub_online_count) = hubs_ready.get_online_count().await {
66-
let hub_number = hubs_ready.len() as u32;
67-
68-
let hub_necessary =
69-
((hub_online_count as f32 * 1.6 / self.hub_template.slots as f32) + 1.0) as u32;
70-
71-
if hub_number < hub_necessary {
72-
self.instance_provider.start_instance(template_name).await?;
73-
}
56+
if hubs_starting.is_empty() {
57+
let hubs_ready = self
58+
.instance_provider
59+
.get_instances(
60+
&InstanceType::Server,
61+
Some(template_name),
62+
Some(&EpsilonState::Running),
63+
)
64+
.await?;
65+
66+
if let Ok(hub_online_count) = hubs_ready.get_online_count().await {
67+
let hub_number = hubs_ready.len() as u32;
68+
69+
let hub_necessary = ((hub_online_count as f32 * 1.6
70+
/ self.hub_template.slots as f32)
71+
+ 1.0) as u32;
72+
73+
if hub_number < hub_necessary {
74+
self.instance_provider.start_instance(template_name).await?;
75+
}
7476

75-
if hub_number > hub_necessary {
76-
if self.time != *DEFAULT_TIME {
77-
self.time += 1;
77+
if hub_number > hub_necessary {
78+
if self.time != *DEFAULT_TIME {
79+
self.time += 1;
7880

79-
return Ok(());
80-
} else {
81-
self.time = 0;
82-
}
81+
return Ok(());
82+
} else {
83+
self.time = 0;
84+
}
8385

84-
let mut n = 0;
85-
let mut hub_option = None;
86+
let mut n = 0;
87+
let mut hub_option = None;
8688

87-
for instance in hubs_ready {
88-
let info_result = instance.get_info().await;
89+
for instance in hubs_ready {
90+
let info_result = instance.get_info().await;
8991

90-
if let Ok(info) = info_result {
91-
let online_player = info.players.online;
92+
if let Ok(info) = info_result {
93+
let online_player = info.players.online;
9294

93-
if instance.get_state() == EpsilonState::Running && online_player <= n {
94-
n = online_player;
95-
hub_option = Some(instance);
95+
if instance.get_state() == EpsilonState::Running
96+
&& online_player <= n
97+
{
98+
n = online_player;
99+
hub_option = Some(instance);
100+
}
96101
}
97102
}
98-
}
99103

100-
if let Some(hub) = hub_option {
101-
let name = hub.get_name();
104+
if let Some(hub) = hub_option {
105+
let name = hub.get_name();
102106

103-
self.instance_provider.remove_instance(name).await?;
107+
self.instance_provider.remove_instance(name).await?;
104108

105-
info!("Hub {} is removed with {} online players", name, n);
109+
info!("Hub {} is removed with {} online players", name, n);
110+
}
106111
}
107112
}
108113
}

0 commit comments

Comments
 (0)