Add support for networked GetSetting to Unified Stack refactor
parent: tbd commit: da6d78e
1 | use Error; |
2 | use ; |
3 | use |
4 | , | AuthenticationTokenGranter
5 | |
6 | , DatabaseSettings, UserAuth, RepositoryBackend, UserBackend, | GitBackend
7 | , |
8 | , |
9 | , | DatabaseBackend
10 | , | InstanceConnections
11 | ; |
12 | |
13 | use Instance; |
14 | |
15 | use ; |
16 | use ; |
17 | use ; |
18 | use |
19 | , | File
20 | , |
21 | , |
22 | , | Mutex
23 | ; |
24 | use ; |
25 | use LocalPoolHandle; |
26 | use Table; |
27 | |
28 | |
29 | extern crate tracing; |
30 | |
31 | |
32 | async |
33 | ; | init
34 | let config: Table = |
35 | let mut file = open .await?; |
36 | let mut text = String new; |
37 | file.read_to_string .await?; |
38 | text.parse? |
39 | ; |
40 | let mut listener = bind .await?; |
41 | let connections: = default; |
42 | let instance_connections: = default; |
43 | let db_conn_options = new |
44 | .host |
45 | .port |
46 | .database |
47 | .username |
48 | .password |
49 | .log_statements; |
50 | let db_pool = connect_with .await?; |
51 | |
52 | debug!; |
53 | ! .run .await?; | migrate
54 | info!; |
55 | |
56 | let settings = new |
57 | pg_pool: db_pool.clone, |
58 | ; |
59 | |
60 | let repository_backend: = |
61 | new |
62 | pg_pool: db_pool.clone, |
63 | repository_folder: String from |
64 | config |
65 | .as_str |
66 | .unwrap, |
67 | , |
68 | instance: from_str |
69 | .unwrap, |
70 | settings_provider: settings.clone, |
71 | ; |
72 | |
73 | let token_granter = new |
74 | config: config.clone, |
75 | instance: from_str .unwrap, |
76 | ; |
77 | |
78 | let user_backend: = new |
79 | db_pool.clone, |
80 | & from_str .unwrap, |
81 | token_granter.clone, |
82 | settings.clone, |
83 | ; |
84 | |
85 | info!; |
86 | |
87 | let database_backend = new |
88 | unwrap, | from_str .
89 | user_backend.clone, |
90 | repository_backend.clone, |
91 | ; |
92 | |
93 | let mut runtime = default; |
94 | |
95 | let database_backend = database_backend.into_substack; |
96 | runtime.merge_builder; |
97 | |
98 | let runtime = new; |
99 | |
100 | let operation_state = |
101 | StackOperationState |
102 | our_instance: from_str |
103 | .unwrap, |
104 | runtime: runtime.clone, |
105 | instance: None, |
106 | user: None, |
107 | |
108 | ; |
109 | |
110 | let pool = new; |
111 | |
112 | loop |
113 | let stream = accept_stream .await; |
114 | info!; |
115 | |
116 | let = match stream |
117 | Ok => stream, |
118 | Err => |
119 | error!; |
120 | continue; |
121 | |
122 | ; |
123 | |
124 | info!; |
125 | |
126 | let connection = accept_websocket_connection .await; |
127 | |
128 | let connection = match connection |
129 | Ok => connection, |
130 | Err => |
131 | error! |
132 | "Failed to initiate Websocket connection from {}. {:?}", |
133 | address, err |
134 | ; |
135 | continue; |
136 | |
137 | ; |
138 | |
139 | info!; |
140 | let connections_cloned = connections.clone; |
141 | let repository_backend = repository_backend.clone; |
142 | let user_backend = user_backend.clone; |
143 | let token_granter = token_granter.clone; |
144 | let settings = settings.clone; |
145 | let instance_connections = instance_connections.clone; |
146 | let config = config.clone; |
147 | let runtime = runtime.clone; |
148 | let operation_state = operation_state.clone; |
149 | |
150 | pool.spawn_pinned |
151 | connection_wrapper |
152 | connection, |
153 | connections_cloned, |
154 | repository_backend, |
155 | user_backend, |
156 | token_granter, |
157 | settings, |
158 | address, |
159 | unwrap, | from_str .
160 | instance_connections, |
161 | config, |
162 | runtime, |
163 | operation_state, |
164 | |
165 | ; |
166 | |
167 | let connection = RawConnection |
168 | task: spawn, |
169 | ; |
170 | |
171 | connections.lock .await.connections.push; |
172 | |
173 | |
174 | |
175 | async |
176 | let stream = listener.accept .await?; |
177 | |
178 | Ok |
179 | |
180 | |
181 | async |
182 | stream: S, |
183 | |
184 | let connection = accept_async .await?; |
185 | |
186 | Ok |
187 | |
188 |