Skip to content

Commit

Permalink
change timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Nov 28, 2023
1 parent 2782418 commit 583659f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/circle-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fetcher.configure({
(url, init, next) =>
retryPromise(async () => {
// This delay is to not put too make sure we don't put too much pressure in circle CI
await new Promise((res) => setTimeout(res, 500));
await new Promise((res) => setTimeout(res, 2000));
const response = await next(url, init);
// console.log(`#${++count}: ${url} ${response.status} @ ${new Date().toISOString()}`);
// console.log(
Expand All @@ -34,6 +34,7 @@ async function retryPromise<T>(fn: () => Promise<T>, retriesLeft = 20, interval
} catch (error) {
if (retriesLeft === 0) throw error;
if (error instanceof ApiError) {
console.error(error.name);
// console.error({
// status: error.status,
// statusText: error.statusText,
Expand Down
1 change: 1 addition & 0 deletions client/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const AMOUNT_OF_DAYS_TO_FETCH = 90;
3 changes: 2 additions & 1 deletion client/fetch-circle-ci-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EnrichedPipeline, getDailyPipelines } from '~/services/circle-ci';
import { addDays } from 'date-fns';
import { getLatestTestResults } from '~/services/test-results';
import { StorybookNpmTag } from '~/model/types';
import { AMOUNT_OF_DAYS_TO_FETCH } from './constants';

export const fetchRawCircleCiData = async ({ useMock = false, branch = 'next-release' } = {}): Promise<EnrichedPipeline[]> => {
if (useMock) {
Expand All @@ -16,7 +17,7 @@ export const fetchRawCircleCiData = async ({ useMock = false, branch = 'next-rel
}

console.log(`Fetching data for the ${branch} branch`);
return getDailyPipelines(branch, addDays(new Date(), -90));
return getDailyPipelines(branch, addDays(new Date(), -AMOUNT_OF_DAYS_TO_FETCH));
};

export const getProcessedTestResults = async (pipelines: EnrichedPipeline[]) => {
Expand Down
3 changes: 2 additions & 1 deletion services/circle-ci.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addDays } from 'date-fns';
import { getJobs, getPipelines, getTestData, getWorkflows, Pipeline } from '~/client/circle-ci';
import { AMOUNT_OF_DAYS_TO_FETCH } from '~/client/constants';

export async function getDailyPipelines(branch = 'next-release', since?: Date): Promise<EnrichedPipeline[]> {
async function getNextPageRecursively(
Expand All @@ -8,7 +9,7 @@ export async function getDailyPipelines(branch = 'next-release', since?: Date):
pageToken?: string | undefined | null
): Promise<EnrichedPipeline[]> {
const createdAt = new Date(pipelines[pipelines.length - 1]?.created_at ?? new Date().getTime());
if (createdAt < (since ?? addDays(new Date(), -90)) || pageToken === null) {
if (createdAt < (since ?? addDays(new Date(), -AMOUNT_OF_DAYS_TO_FETCH)) || pageToken === null) {
return await Promise.all(enrichedPipelines);
}

Expand Down
3 changes: 2 additions & 1 deletion services/test-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EnrichedPipeline, getDailyPipelines } from './circle-ci';
import { Feature, TemplateConfig, TemplateTests, TestResult } from '../model/types';
import { range } from '../util';
import { addDays, isSameDay } from 'date-fns';
import { AMOUNT_OF_DAYS_TO_FETCH } from '~/client/constants';

interface Context {
getDailyPipelines: typeof getDailyPipelines;
Expand All @@ -20,7 +21,7 @@ export async function getLatestTestResults(ctx: Context): Promise<TemplateTests[
const pipelines: EnrichedPipeline[] = await ctx.getDailyPipelines('next');
const now = ctx.now();

const last90Days = range(0, 90).map((i) => addDays(now, -90 + i));
const last90Days = range(0, AMOUNT_OF_DAYS_TO_FETCH).map((i) => addDays(now, -AMOUNT_OF_DAYS_TO_FETCH + i));
const days = last90Days.map((day) => enrichDayWithData(day, pipelines));
const allTemplates = Array.from(new Set(days.map((it) => it.templates?.map((it) => it.template).flat() ?? []).flat()));

Expand Down

0 comments on commit 583659f

Please sign in to comment.