Track how much time people spend waiting for queues to be flushed

Summary: Added stats, so that we know how much people have to wait when opening plugin after we open the queue GK

Reviewed By: jknoxville

Differential Revision: D19598730

fbshipit-source-id: f955123f2bae5b870eada8f787385d6c0450453e
This commit is contained in:
Michel Weststrate
2020-01-28 05:03:50 -08:00
committed by Facebook Github Bot
parent 0ed95f2a99
commit bdd4516dc4
2 changed files with 17 additions and 5 deletions

View File

@@ -192,7 +192,7 @@ class PluginContainer extends PureComponent<Props, State> {
pluginKey &&
pendingMessages?.length
) {
// this.setState({progress: {current: 0, total: 0}});
const start = Date.now();
this.idler = new Idler();
processMessageQueue(
activePlugin,
@@ -202,7 +202,18 @@ class PluginContainer extends PureComponent<Props, State> {
this.setState({progress});
},
this.idler,
).then(completed => {
const duration = Date.now() - start;
this.props.logger.track(
'duration',
'queue-processing-before-plugin-open',
{
completed,
duration,
},
activePlugin.id,
);
});
}
}
}

View File

@@ -204,9 +204,9 @@ export async function processMessageQueue(
store: MiddlewareAPI,
progressCallback?: (progress: {current: number; total: number}) => void,
idler: BaseIdler = new Idler(),
) {
): Promise<boolean> {
if (!plugin.persistedStateReducer) {
return;
return true;
}
const total = getPendingMessages(store, pluginKey).length;
let progress = 0;
@@ -249,12 +249,13 @@ export async function processMessageQueue(
}
if (idler.isCancelled()) {
return;
return false;
}
await idler.idle();
// new messages might have arrived, so keep looping
} while (getPendingMessages(store, pluginKey).length);
return true;
}
function getPendingMessages(