-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoadBalancer.gd
51 lines (35 loc) · 1.13 KB
/
LoadBalancer.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
extends "res://Server.gd"
signal backend_config_changed
var backend_config = []
var config = {}
func _init():
type = "LoadBalancer"
config_warning = true
accepted_content_types = ['dynamic', 'static']
func _on_saveButton_pressed():
_save_config('static_backend_config')
_save_config('dynamic_backend_config')
func _save_config(config_type):
config[config_type] = $Meta/ConfigWindow/Servers.get_node(config_type).text.split('\n')
if len(config[config_type]):
config_warning = false
for b in config[config_type]:
if not b in level.iptable:
config_warning = true
if config_warning == false:
$Meta/ConfigWindow/Servers.get_node(config_type).modulate = Color(1,1,1,1)
#move to Server
func process_request(req):
if req.type == 'dynamic':
backend_config = config['dynamic_backend_config']
else:
backend_config = config['static_backend_config']
var server = backend_config[randi() % backend_config.size()]
if req.response:
req.route.pop_back()
else:
req.route.append(server)
yield(calculate_response_time(), "completed")
req.send(100)
var response = yield(req, 'processed')
return response