@@ -82,9 +82,10 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
82
82
'${record .loggerName }: ${record .message }' ,
83
83
);
84
84
});
85
+ _log.info ('[INIT_SEQ] 1. Logger setup complete.' );
85
86
86
87
// 2. Establish Database Connection
87
- _log.info ('Connecting to PostgreSQL database...' );
88
+ _log.info ('[INIT_SEQ] 2. Connecting to PostgreSQL database...' );
88
89
final dbUri = Uri .parse (EnvironmentConfig .databaseUrl);
89
90
String ? username;
90
91
String ? password;
@@ -106,18 +107,24 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
106
107
),
107
108
settings: const ConnectionSettings (sslMode: SslMode .require),
108
109
);
109
- _log.info ('PostgreSQL database connection established.' );
110
+ _log.info ('[INIT_SEQ] 2. PostgreSQL database connection established.' );
110
111
111
112
// 3. Initialize and run database seeding
113
+ _log.info ('[INIT_SEQ] 3. Initializing database seeding service...' );
112
114
final seedingService = DatabaseSeedingService (
113
115
connection: _connection,
114
116
log: _log,
115
117
);
118
+ _log.info ('[INIT_SEQ] 3. Creating tables if they do not exist...' );
116
119
await seedingService.createTables ();
120
+ _log.info ('[INIT_SEQ] 3. Seeding global fixture data...' );
117
121
await seedingService.seedGlobalFixtureData ();
122
+ _log.info ('[INIT_SEQ] 3. Seeding initial admin and config...' );
118
123
await seedingService.seedInitialAdminAndConfig ();
119
-
120
- // 4. Initialize Repositories
124
+ _log
125
+ ..info ('[INIT_SEQ] 3. Database seeding complete.' )
126
+ // 4. Initialize Repositories
127
+ ..info ('[INIT_SEQ] 4. Initializing data repositories...' );
121
128
final headlineRepository = _createRepository <Headline >(
122
129
tableName: 'headlines' ,
123
130
fromJson: Headline .fromJson,
@@ -159,8 +166,10 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
159
166
fromJson: AppConfig .fromJson,
160
167
toJson: (c) => c.toJson (),
161
168
);
162
-
163
- // 5. Initialize Services
169
+ _log
170
+ ..info ('[INIT_SEQ] 4. Data repositories initialized.' )
171
+ // 5. Initialize Services
172
+ ..info ('[INIT_SEQ] 5. Initializing services...' );
164
173
const emailRepository = HtEmailRepository (
165
174
emailClient: HtEmailInMemoryClient (),
166
175
);
@@ -181,19 +190,20 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
181
190
userContentPreferencesRepository: userContentPreferencesRepository,
182
191
uuidGenerator: const Uuid (),
183
192
);
184
- final dashboardSummaryService =
185
- DashboardSummaryService (
186
- headlineRepository: headlineRepository,
187
- categoryRepository: categoryRepository,
188
- sourceRepository: sourceRepository,
189
- );
193
+ final dashboardSummaryService = DashboardSummaryService (
194
+ headlineRepository: headlineRepository,
195
+ categoryRepository: categoryRepository,
196
+ sourceRepository: sourceRepository,
197
+ );
190
198
const permissionService = PermissionService ();
191
199
final UserPreferenceLimitService userPreferenceLimitService =
192
200
DefaultUserPreferenceLimitService (
193
201
appConfigRepository: appConfigRepository,
194
202
);
195
-
196
- // 6. Populate the DependencyContainer
203
+ _log
204
+ ..info ('[INIT_SEQ] 5. Services initialized.' )
205
+ // 6. Populate the DependencyContainer
206
+ ..info ('[INIT_SEQ] 6. Populating dependency container...' );
197
207
DependencyContainer .instance.init (
198
208
headlineRepository: headlineRepository,
199
209
categoryRepository: categoryRepository,
@@ -214,21 +224,25 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
214
224
);
215
225
216
226
// 7. Start the server with the gated handler
227
+ _log.info ('[INIT_SEQ] 7. Starting server with gated handler...' );
217
228
final server = await serve (gatedHandler, ip, port);
218
- _log.info ('Server listening on port ${server .port }' );
229
+ _log.info ('[INIT_SEQ] 7. Server listening on port ${server .port }' );
219
230
220
231
// 8. Open the gate now that the server is ready.
232
+ _log.info ('[INIT_SEQ] 8. Server ready. Opening request gate.' );
221
233
initCompleter.complete ();
222
234
223
235
// 9. Handle graceful shutdown
236
+ _log.info ('[INIT_SEQ] 9. Registering graceful shutdown handler.' );
224
237
ProcessSignal .sigint.watch ().listen ((_) async {
225
- _log.info ('Received SIGINT. Shutting down...' );
238
+ _log.info ('[SHUTDOWN] Received SIGINT. Shutting down...' );
226
239
await _connection.close ();
227
- _log.info ('Database connection closed.' );
240
+ _log.info ('[SHUTDOWN] Database connection closed.' );
228
241
await server.close (force: true );
229
- _log.info ('Server shut down.' );
242
+ _log.info ('[SHUTDOWN] Server shut down.' );
230
243
exit (0 );
231
244
});
245
+ _log.info ('[INIT_SEQ] Server initialization sequence complete.' );
232
246
233
247
return server;
234
248
}
0 commit comments