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