Skip to content

Commit 8324569

Browse files
committed
Ensure events database is initialized _after_ upload state is dealt with
1 parent 51d6e89 commit 8324569

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

glean/src/core/glean.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,19 @@ class Glean {
239239
Context.debugOptions = correctConfig.debug;
240240
Glean.instance._config = correctConfig;
241241

242-
243-
// IMPORTANT!
244-
// Any pings we want to send upon initialization should happen before these two lines.
245-
//
246-
// Clear application lifetime metrics.
247-
await Context.metricsDatabase.clear(Lifetime.Application);
248-
// Initialize the events database.
249-
await Context.eventsDatabase.initialize();
250-
251242
// We need to mark Glean as initialized before dealing with the upload status,
252243
// otherwise we will not be able to submit deletion-request pings if necessary.
253244
//
254245
// This is fine, we are inside a dispatched task that is guaranteed to run before any
255246
// other task. No external API call will be executed before we leave this task.
256247
Context.initialized = true;
257248

249+
// IMPORTANT!
250+
// Any pings we want to send upon initialization should happen before this line.
251+
//
252+
// Clear application lifetime metrics.
253+
await Context.metricsDatabase.clear(Lifetime.Application);
254+
258255
// The upload enabled flag may have changed since the last run, for
259256
// example by the changing of a config file.
260257
if (uploadEnabled) {
@@ -285,9 +282,16 @@ class Glean {
285282
}
286283
}
287284

285+
// Initialize the events database.
286+
//
287+
// It's important this happens _after_ the upload state is dealt with,
288+
// because initializing the events database may record the execution_counter and
289+
// glean.restarted metrics. If the upload state is not defined these metrics can't be recorded.
290+
await Context.eventsDatabase.initialize();
291+
288292
// We only scan the pendings pings **after** dealing with the upload state.
289-
// If upload is disabled, we delete all pending pings files
290-
// and we need to do that **before** scanning the pending pings
293+
// If upload is disabled, pending pings files are deleted
294+
// so we need to know that state **before** scanning the pending pings
291295
// to ensure we don't enqueue pings before their files are deleted.
292296
await Context.pingsDatabase.scanPendingPings();
293297
});

0 commit comments

Comments
 (0)