Skip to content

Commit

Permalink
chore(telemetry): Flush more often with gatsby develop (#32015)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamo authored Jun 28, 2021
1 parent 2eb57c7 commit 51804a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/gatsby-telemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import time, { TimeUnit } from "@turist/time"

const instance = new AnalyticsTracker()

const flush = createFlush(instance.isTrackingEnabled())
export const flush = createFlush(instance.isTrackingEnabled())

process.on(`exit`, flush)

Expand Down Expand Up @@ -124,19 +124,20 @@ export {
}

module.exports = {
trackFeatureIsUsed,
trackCli,
addSiteMeasurement,
aggregateStats,
captureEvent,
trackError,
trackBuildError,
setDefaultTags,
decorateEvent,
setTelemetryEnabled,
startBackgroundUpdate,
isTrackingEnabled,
aggregateStats,
addSiteMeasurement,
expressMiddleware,
flush,
isTrackingEnabled,
setDefaultComponentId,
setDefaultTags,
setGatsbyCliVersion,
setTelemetryEnabled,
startBackgroundUpdate,
trackBuildError,
trackCli,
trackError,
trackFeatureIsUsed,
}
11 changes: 11 additions & 0 deletions packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import reporter from "gatsby-cli/lib/reporter"
import { getSslCert } from "../utils/get-ssl-cert"
import { IProxyControls, startDevelopProxy } from "../utils/develop-proxy"
import { IProgram, IDebugInfo } from "./types"
import { flush as telemetryFlush } from "gatsby-telemetry"

// Adapted from https://stackoverflow.com/a/16060619
const requireUncached = (file: string): any => {
Expand Down Expand Up @@ -392,6 +393,11 @@ module.exports = async (program: IProgram): Promise<void> => {
// This needs to be propagated back to the parent process
developProcess.onExit(
(code: number | null, signal: NodeJS.Signals | null) => {
try {
telemetryFlush()
} catch (e) {
// nop
}
if (isRestarting) return
if (signal !== null) {
process.kill(process.pid, signal)
Expand Down Expand Up @@ -519,6 +525,11 @@ function shutdownServices(
}: IShutdownServicesOptions,
signal: NodeJS.Signals
): Promise<void> {
try {
telemetryFlush()
} catch (e) {
// nop
}
const services = [
developProcess.stop(signal),
telemetryServerProcess.stop(),
Expand Down

0 comments on commit 51804a0

Please sign in to comment.