mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 20:55:39 +00:00
Bug 1344741 - Update TelemetrySend.jsm to async function & await. r=gfritzsche
This commit is contained in:
parent
92937b757e
commit
4dae2debd4
@ -392,7 +392,7 @@ var SendScheduler = {
|
|||||||
return this._sendTask;
|
return this._sendTask;
|
||||||
},
|
},
|
||||||
|
|
||||||
_doSendTask: Task.async(function*() {
|
async _doSendTask() {
|
||||||
this._sendTaskState = "send task started";
|
this._sendTaskState = "send task started";
|
||||||
this._backoffDelay = SEND_TICK_DELAY;
|
this._backoffDelay = SEND_TICK_DELAY;
|
||||||
this._sendsFailed = false;
|
this._sendsFailed = false;
|
||||||
@ -440,7 +440,7 @@ var SendScheduler = {
|
|||||||
this._sendTaskState = "wait for throttling to pass";
|
this._sendTaskState = "wait for throttling to pass";
|
||||||
|
|
||||||
const delay = nextPingSendTime - now.getTime();
|
const delay = nextPingSendTime - now.getTime();
|
||||||
const cancelled = yield CancellableTimeout.promiseWaitOnTimeout(delay);
|
const cancelled = await CancellableTimeout.promiseWaitOnTimeout(delay);
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
this._log.trace("_doSendTask - throttling wait was cancelled, resetting backoff timer");
|
this._log.trace("_doSendTask - throttling wait was cancelled, resetting backoff timer");
|
||||||
resetBackoffTimer();
|
resetBackoffTimer();
|
||||||
@ -457,7 +457,7 @@ var SendScheduler = {
|
|||||||
this._sendsFailed = false;
|
this._sendsFailed = false;
|
||||||
const sendStartTime = Policy.now();
|
const sendStartTime = Policy.now();
|
||||||
this._sendTaskState = "wait on ping sends";
|
this._sendTaskState = "wait on ping sends";
|
||||||
yield TelemetrySendImpl.sendPings(current, sending.map(p => p.id));
|
await TelemetrySendImpl.sendPings(current, sending.map(p => p.id));
|
||||||
if (this._shutdown || (TelemetrySend.pendingPingCount == 0)) {
|
if (this._shutdown || (TelemetrySend.pendingPingCount == 0)) {
|
||||||
this._log.trace("_doSendTask - bailing out after sending, shutdown: " + this._shutdown +
|
this._log.trace("_doSendTask - bailing out after sending, shutdown: " + this._shutdown +
|
||||||
", pendingPingCount: " + TelemetrySend.pendingPingCount);
|
", pendingPingCount: " + TelemetrySend.pendingPingCount);
|
||||||
@ -487,13 +487,13 @@ var SendScheduler = {
|
|||||||
|
|
||||||
this._log.trace("_doSendTask - waiting for next send opportunity, timeout is " + nextSendDelay)
|
this._log.trace("_doSendTask - waiting for next send opportunity, timeout is " + nextSendDelay)
|
||||||
this._sendTaskState = "wait on next send opportunity";
|
this._sendTaskState = "wait on next send opportunity";
|
||||||
const cancelled = yield CancellableTimeout.promiseWaitOnTimeout(nextSendDelay);
|
const cancelled = await CancellableTimeout.promiseWaitOnTimeout(nextSendDelay);
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
this._log.trace("_doSendTask - batch send wait was cancelled, resetting backoff timer");
|
this._log.trace("_doSendTask - batch send wait was cancelled, resetting backoff timer");
|
||||||
resetBackoffTimer();
|
resetBackoffTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper calculates the next time that we can send pings at.
|
* This helper calculates the next time that we can send pings at.
|
||||||
@ -581,7 +581,7 @@ var TelemetrySendImpl = {
|
|||||||
this._testMode = testing;
|
this._testMode = testing;
|
||||||
},
|
},
|
||||||
|
|
||||||
setup: Task.async(function*(testing) {
|
async setup(testing) {
|
||||||
this._log.trace("setup");
|
this._log.trace("setup");
|
||||||
|
|
||||||
this._testMode = testing;
|
this._testMode = testing;
|
||||||
@ -594,7 +594,7 @@ var TelemetrySendImpl = {
|
|||||||
|
|
||||||
// Check the pending pings on disk now.
|
// Check the pending pings on disk now.
|
||||||
try {
|
try {
|
||||||
yield this._checkPendingPings();
|
await this._checkPendingPings();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this._log.error("setup - _checkPendingPings rejected", ex);
|
this._log.error("setup - _checkPendingPings rejected", ex);
|
||||||
}
|
}
|
||||||
@ -605,15 +605,15 @@ var TelemetrySendImpl = {
|
|||||||
|
|
||||||
// Start sending pings, but don't block on this.
|
// Start sending pings, but don't block on this.
|
||||||
SendScheduler.triggerSendingPings(true);
|
SendScheduler.triggerSendingPings(true);
|
||||||
}),
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discard old pings from the pending pings and detect overdue ones.
|
* Discard old pings from the pending pings and detect overdue ones.
|
||||||
* @return {Boolean} True if we have overdue pings, false otherwise.
|
* @return {Boolean} True if we have overdue pings, false otherwise.
|
||||||
*/
|
*/
|
||||||
_checkPendingPings: Task.async(function*() {
|
async _checkPendingPings() {
|
||||||
// Scan the pending pings - that gives us a list sorted by last modified, descending.
|
// Scan the pending pings - that gives us a list sorted by last modified, descending.
|
||||||
let infos = yield TelemetryStorage.loadPendingPingList();
|
let infos = await TelemetryStorage.loadPendingPingList();
|
||||||
this._log.info("_checkPendingPings - pending ping count: " + infos.length);
|
this._log.info("_checkPendingPings - pending ping count: " + infos.length);
|
||||||
if (infos.length == 0) {
|
if (infos.length == 0) {
|
||||||
this._log.trace("_checkPendingPings - no pending pings");
|
this._log.trace("_checkPendingPings - no pending pings");
|
||||||
@ -633,9 +633,9 @@ var TelemetrySendImpl = {
|
|||||||
Utils.millisecondsToDays(Math.abs(now.getTime() - pingInfo.lastModificationDate));
|
Utils.millisecondsToDays(Math.abs(now.getTime() - pingInfo.lastModificationDate));
|
||||||
Telemetry.getHistogramById("TELEMETRY_PENDING_PINGS_AGE").add(ageInDays);
|
Telemetry.getHistogramById("TELEMETRY_PENDING_PINGS_AGE").add(ageInDays);
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
|
|
||||||
shutdown: Task.async(function*() {
|
async shutdown() {
|
||||||
this._shutdown = true;
|
this._shutdown = true;
|
||||||
|
|
||||||
for (let topic of this.OBSERVER_TOPICS) {
|
for (let topic of this.OBSERVER_TOPICS) {
|
||||||
@ -650,17 +650,17 @@ var TelemetrySendImpl = {
|
|||||||
this._sendingEnabled = false;
|
this._sendingEnabled = false;
|
||||||
|
|
||||||
// Cancel any outgoing requests.
|
// Cancel any outgoing requests.
|
||||||
yield this._cancelOutgoingRequests();
|
await this._cancelOutgoingRequests();
|
||||||
|
|
||||||
// Stop any active send tasks.
|
// Stop any active send tasks.
|
||||||
yield SendScheduler.shutdown();
|
await SendScheduler.shutdown();
|
||||||
|
|
||||||
// Wait for any outstanding async ping activity.
|
// Wait for any outstanding async ping activity.
|
||||||
yield this.promisePendingPingActivity();
|
await this.promisePendingPingActivity();
|
||||||
|
|
||||||
// Save any outstanding pending pings to disk.
|
// Save any outstanding pending pings to disk.
|
||||||
yield this._persistCurrentPings();
|
await this._persistCurrentPings();
|
||||||
}),
|
},
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this._log.trace("reset");
|
this._log.trace("reset");
|
||||||
@ -811,7 +811,7 @@ var TelemetrySendImpl = {
|
|||||||
*
|
*
|
||||||
* @return Promise A promise that is resolved when all pings finished sending or failed.
|
* @return Promise A promise that is resolved when all pings finished sending or failed.
|
||||||
*/
|
*/
|
||||||
_sendPersistedPings: Task.async(function*(pingIds) {
|
async _sendPersistedPings(pingIds) {
|
||||||
this._log.trace("sendPersistedPings");
|
this._log.trace("sendPersistedPings");
|
||||||
|
|
||||||
if (TelemetryStorage.pendingPingCount < 1) {
|
if (TelemetryStorage.pendingPingCount < 1) {
|
||||||
@ -838,8 +838,8 @@ var TelemetrySendImpl = {
|
|||||||
|
|
||||||
let promise = Promise.all(pingSendPromises);
|
let promise = Promise.all(pingSendPromises);
|
||||||
this._trackPendingPingTask(promise);
|
this._trackPendingPingTask(promise);
|
||||||
yield promise;
|
await promise;
|
||||||
}),
|
},
|
||||||
|
|
||||||
_onPingRequestFinished(success, startTime, id, isPersisted) {
|
_onPingRequestFinished(success, startTime, id, isPersisted) {
|
||||||
this._log.trace("_onPingRequestFinished - success: " + success + ", persisted: " + isPersisted);
|
this._log.trace("_onPingRequestFinished - success: " + success + ", persisted: " + isPersisted);
|
||||||
@ -1088,10 +1088,10 @@ var TelemetrySendImpl = {
|
|||||||
return Promise.all(p);
|
return Promise.all(p);
|
||||||
},
|
},
|
||||||
|
|
||||||
_persistCurrentPings: Task.async(function*() {
|
async _persistCurrentPings() {
|
||||||
for (let [id, ping] of this._currentPings) {
|
for (let [id, ping] of this._currentPings) {
|
||||||
try {
|
try {
|
||||||
yield savePing(ping);
|
await savePing(ping);
|
||||||
this._log.trace("_persistCurrentPings - saved ping " + id);
|
this._log.trace("_persistCurrentPings - saved ping " + id);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this._log.error("_persistCurrentPings - failed to save ping " + id, ex);
|
this._log.error("_persistCurrentPings - failed to save ping " + id, ex);
|
||||||
@ -1099,7 +1099,7 @@ var TelemetrySendImpl = {
|
|||||||
this._currentPings.delete(id);
|
this._currentPings.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current pending, not yet persisted, pings, newest first.
|
* Returns the current pending, not yet persisted, pings, newest first.
|
||||||
|
Loading…
Reference in New Issue
Block a user