Skip to content

Commit

Permalink
refactor: trigger data refresher manually (#731)
Browse files Browse the repository at this point in the history
* fix: check for value before manipulation

* fix: run background refresher on demand

* refactor: move all refresher init in same place
  • Loading branch information
wa0x6e authored Oct 28, 2023
1 parent efe8f61 commit cf26dfe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/helpers/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function loadModerationData() {
flaggedLinks = res?.flaggedLinks;
}

async function run() {
export default async function run() {
try {
await loadModerationData();
consecutiveFailsCount = 0;
Expand All @@ -28,5 +28,3 @@ async function run() {
await snapshot.utils.sleep(5e3);
run();
}

run();
4 changes: 1 addition & 3 deletions src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export async function getSpace(id: string) {
};
}

async function run() {
export default async function run() {
try {
await loadSpaces();
await loadSpacesMetrics();
Expand All @@ -187,5 +187,3 @@ async function run() {
await snapshot.utils.sleep(360e3);
run();
}

run();
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import rateLimit from './helpers/rateLimit';
import log from './helpers/log';
import initMetrics from './helpers/metrics';
import { checkKeycard } from './helpers/keycard';
import './helpers/moderation';
import refreshModerationData from './helpers/moderation';
import refreshSpacesCache from './helpers/spaces';
import './helpers/strategies';

const app = express();
const PORT = process.env.PORT || 3000;

initLogger(app);
initMetrics(app);
refreshModerationData();
refreshSpacesCache();

app.disable('x-powered-by');
app.use(express.json({ limit: '20mb' }));
Expand Down

0 comments on commit cf26dfe

Please sign in to comment.