-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new options endpoint (#940)
* feat: add new options endpoint * fix: cache result for 2 minutes * Update src/graphql/operations/options.ts * fix: fix wrong interval value --------- Co-authored-by: Chaitanya <[email protected]>
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { capture } from '@snapshot-labs/snapshot-sentry'; | ||
import snapshot from '@snapshot-labs/snapshot.js'; | ||
import log from '../../helpers/log'; | ||
import db from '../../helpers/mysql'; | ||
|
||
const RUN_INTERVAL = 120e3; | ||
|
||
let options = []; | ||
|
||
export default async function () { | ||
return options; | ||
} | ||
|
||
async function loadOptions() { | ||
options = await db.queryAsync('SELECT s.* FROM options s'); | ||
} | ||
|
||
async function run() { | ||
try { | ||
log.info('[options] Start options refresh'); | ||
await loadOptions(); | ||
log.info(`[options] ${options.length} options reloaded`); | ||
log.info('[options] End options refresh'); | ||
} catch (e: any) { | ||
capture(e); | ||
log.error(`[options] failed to refresh options, ${JSON.stringify(e)}`); | ||
} | ||
await snapshot.utils.sleep(RUN_INTERVAL); | ||
run(); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters