@@ -6,6 +6,7 @@ import { DEFAULT_TELEMETRY_ENDPOINT } from "./constants";
66import Configuration from "config" ;
77import MetricsDatabase from "metrics/database" ;
88import PingsDatabase from "pings/database" ;
9+ import PingUploader from "upload" ;
910import { isUndefined , sanitizeApplicationId } from "utils" ;
1011import { CoreMetrics } from "internal_metrics" ;
1112import { Lifetime } from "metrics" ;
@@ -25,6 +26,8 @@ class Glean {
2526 private _initialized : boolean ;
2627 // Instances of Glean's core metrics.
2728 private _coreMetrics : CoreMetrics ;
29+ // The ping uploader.
30+ private _pingUploader : PingUploader
2831
2932 // Properties that will only be set on `initialize`.
3033 private _applicationId ?: string ;
@@ -37,16 +40,21 @@ class Glean {
3740 Use Glean.instance instead to access the Glean singleton.` ) ;
3841 }
3942
43+ this . _pingUploader = new PingUploader ( ) ;
4044 this . _coreMetrics = new CoreMetrics ( ) ;
4145 this . _initialized = false ;
4246 this . _db = {
4347 metrics : new MetricsDatabase ( ) ,
44- pings : new PingsDatabase ( )
48+ pings : new PingsDatabase ( this . _pingUploader )
4549 } ;
4650 // Temporarily setting this to true always, until Bug 1677444 is resolved.
4751 this . _uploadEnabled = true ;
4852 }
4953
54+ private static get pingUploader ( ) : PingUploader {
55+ return Glean . instance . _pingUploader ;
56+ }
57+
5058 private static get coreMetrics ( ) : CoreMetrics {
5159 return Glean . instance . _coreMetrics ;
5260 }
@@ -77,6 +85,10 @@ class Glean {
7785 await Glean . coreMetrics . initialize ( config ?. appBuild , config ?. appDisplayVersion ) ;
7886
7987 Glean . instance . _initialized = true ;
88+
89+ await Glean . pingUploader . scanPendingPings ( ) ;
90+ // Even though this returns a promise, there is no need to block on it returning.
91+ Glean . pingUploader . triggerUpload ( ) ;
8092 }
8193
8294 /**
@@ -158,11 +170,15 @@ class Glean {
158170 Glean . instance . _initialized = false ;
159171 // Reset upload enabled state, not to inerfere with other tests.
160172 Glean . uploadEnabled = true ;
173+
174+ // Stop ongoing jobs and clear pending pings queue.
175+ await Glean . pingUploader . clearPendingPingsQueue ( ) ;
176+
161177 // Clear the databases.
162178 await Glean . metricsDatabase . clearAll ( ) ;
163179 await Glean . pingsDatabase . clearAll ( ) ;
164180
165- // Initialize Glean.
181+ // Re- Initialize Glean.
166182 await Glean . initialize ( applicationId , config ) ;
167183 }
168184}
0 commit comments