Skip to content

Commit

Permalink
Add mostRecentSuccessfulFetchAt
Browse files Browse the repository at this point in the history
This can give clients an idea of how long its been since the last successful fetch
  • Loading branch information
benweatherman committed Jun 15, 2022
1 parent 4b52be2 commit 0434ecd
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export type FailureToFetchSupergraphSdlAfterInit = ({
graphRef,
logger,
fetchCount,
}: FailureToFetchSupergraphSdlFunctionParams) => Promise<string | null>;
mostRecentSuccessfulFetchAt,
}:
| FailureToFetchSupergraphSdlFunctionParams
& { mostRecentSuccessfulFetchAt?: Date }) => Promise<string | null>;

type State =
| { phase: 'constructed' }
Expand Down Expand Up @@ -79,6 +82,7 @@ export class UplinkSupergraphManager implements SupergraphManager {
private fetchCount: number = 0;
private minDelayMs: number | null = null;
private earliestFetchTime: Date | null = null;
private mostRecentSuccessfulFetchAt?: Date;

constructor({
apiKey,
Expand Down Expand Up @@ -211,6 +215,7 @@ export class UplinkSupergraphManager implements SupergraphManager {
this.compositionId = result.id;

({ supergraphSdl, minDelaySeconds } = result);
this.mostRecentSuccessfulFetchAt = new Date();
} catch (e) {
this.logger.debug(
`Error fetching supergraphSdl from Uplink during phase '${this.state.phase}'`,
Expand All @@ -235,6 +240,7 @@ export class UplinkSupergraphManager implements SupergraphManager {
graphRef: this.graphRef,
logger: this.logger,
fetchCount: this.fetchCount,
mostRecentSuccessfulFetchAt: this.mostRecentSuccessfulFetchAt,
});

// This is really an error, but we'll let the caller decide what to do with it
Expand Down

0 comments on commit 0434ecd

Please sign in to comment.