startPollingForContentUpdates = helpers => {
  if (
    startedPolling ||
    process.env.WP_DISABLE_POLLING ||
    process.env.ENABLE_GATSBY_REFRESH_ENDPOINT
  ) {
    return
  }

  startedPolling = true

  const { verbose, develop } = getStore().getState().gatsbyApi.pluginOptions
  const restoreContext = snapshotContext()
  const msRefetchInterval = develop.nodeUpdateInterval

  helpers.emitter.on(`COMPILATION_DONE`, () => {
    /**
     * we only want to start our refetcher helper 1 time after the first COMPILATION_DONE event.
     * This event happens when the dev server is ready. It also happens after saving a code change. We only want to run our code 1 time.
     * onCreateDevServer (the node API we're hooking into) is called before the dev server is ready.
     * Running our logic at that point is problematic because we could end up triggering the WEBHOOK_RECEIVED event before the dev server is ready and this can cause Gatsby to throw errors. So we're hooking into COMPILATION_DONE to avoid that problem.
     */
    if (!firstCompilationDone) {
      firstCompilationDone = true

      // wait a second so that terminal output is more smooth
      setTimeout(() => {
        if (verbose) {
          // I'm not sure why, but we're losing the ALS context here so we need to restore it manually
          restoreContext()
          helpers.reporter.log(``)
          helpers.reporter.info(
            formatLogMessage`Watching for WordPress changes`
          )
        }

        refetcher(msRefetchInterval, helpers)
      }, 1000)
    }
  })
}
Starts constantly refetching the latest WordPress changes
so we can update Gatsby nodes when data changes