From 227d1d4cb7a99d190ebac5004c6762df9db7afc7 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 11 Sep 2018 11:05:35 +0200 Subject: [PATCH] refactor(github): improve graphql logging and retries --- lib/platform/github/gh-got-wrapper.js | 10 ++++++++++ lib/platform/github/index.js | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/platform/github/gh-got-wrapper.js b/lib/platform/github/gh-got-wrapper.js index e3344e819a..3d09a0ccdf 100644 --- a/lib/platform/github/gh-got-wrapper.js +++ b/lib/platform/github/gh-got-wrapper.js @@ -78,6 +78,16 @@ async function get(path, options, retries = 5) { ) { cache[path] = res; } + // istanbul ignore if + if (method === 'POST' && path === 'graphql') { + if (res.errors && retries > 0) { + logger.info('Retrying graphql query'); + return get(path, opts, 0); + } + if (res.data && retries === 0) { + logger.info('Recovered graphql query'); + } + } return res; } catch (err) { if ( diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index 2a55cca7af..13dedf2c0e 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -893,7 +893,7 @@ async function getOpenPrs() { const prNumbers = []; // istanbul ignore if if (!res.data) { - logger.warn({ res }, 'No graphql res.data'); + logger.warn({ query, res }, 'No graphql res.data'); return {}; } for (const pr of res.data.repository.pullRequests.nodes) { @@ -995,7 +995,7 @@ async function getClosedPrs() { const prNumbers = []; // istanbul ignore if if (!res.data) { - logger.warn({ res }, 'No graphql res.data'); + logger.warn({ query, res }, 'No graphql res.data'); return {}; } for (const pr of res.data.repository.pullRequests.nodes) { -- GitLab