Skip to content

Commit

Permalink
chore: minor changes in pat info (anuraghazra#2481)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra authored and dev-onejun committed Jan 28, 2023
1 parent 4327b1c commit 88bb25e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 11 additions & 3 deletions api/status/pat-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { logger, request, dateDiff } from "../../src/common/utils.js";
export const RATE_LIMIT_SECONDS = 60 * 10; // 1 request per 10 minutes
export const RATE_LIMIT_SECONDS = 60 * 5; // 1 request per 10 minutes

/**
* Simple uptime check fetcher for the PATs.
Expand Down Expand Up @@ -98,12 +98,20 @@ const getPATInfo = async (fetcher, variables) => {
return Object.keys(details).filter((pat) => details[pat].status === status);
};

const sortedDetails = Object.keys(details)
.sort()
.reduce((obj, key) => {
obj[key] = details[key];
return obj;
}, {});

return {
validPATs: filterPATsByStatus("valid"),
expiredPATs: filterPATsByStatus("expired"),
exhaustedPATS: filterPATsByStatus("exhausted"),
exhaustedPATs: filterPATsByStatus("exhausted"),
suspendedPATs: filterPATsByStatus("suspended"),
errorPATs: filterPATsByStatus("error"),
details,
details: sortedDetails,
};
};

Expand Down
9 changes: 6 additions & 3 deletions tests/pat-info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ describe("Test /api/status/pat-info", () => {
{
validPATs: ["PAT_2", "PAT_3", "PAT_4"],
expiredPATs: [],
exhaustedPATS: ["PAT_1"],
exhaustedPATs: ["PAT_1"],
suspendedPATs: [],
errorPATs: [],
details: {
PAT_1: {
Expand Down Expand Up @@ -132,7 +133,8 @@ describe("Test /api/status/pat-info", () => {
{
validPATs: ["PAT_2", "PAT_3", "PAT_4"],
expiredPATs: [],
exhaustedPATS: [],
exhaustedPATs: [],
suspendedPATs: [],
errorPATs: ["PAT_1"],
details: {
PAT_1: {
Expand Down Expand Up @@ -178,7 +180,8 @@ describe("Test /api/status/pat-info", () => {
{
validPATs: ["PAT_2", "PAT_3", "PAT_4"],
expiredPATs: ["PAT_1"],
exhaustedPATS: [],
exhaustedPATs: [],
suspendedPATs: [],
errorPATs: [],
details: {
PAT_1: {
Expand Down

1 comment on commit 88bb25e

@vercel
Copy link

@vercel vercel bot commented on 88bb25e Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.