-
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.
- Loading branch information
Showing
1 changed file
with
24 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
import snapshot from '@snapshot-labs/snapshot.js'; | ||
import { capture } from '@snapshot-labs/snapshot-sentry'; | ||
import log from '../../helpers/log'; | ||
import db from '../../helpers/mysql'; | ||
|
||
export default async function (_, args) { | ||
const RUN_INTERVAL = 12e3; | ||
|
||
let options = []; | ||
|
||
export default async function () { | ||
return options; | ||
} | ||
|
||
async function loadOptions() { | ||
options = await db.queryAsync('SELECT s.* FROM options s'); | ||
} | ||
|
||
async function run() { | ||
try { | ||
return await db.queryAsync('SELECT s.* FROM options s'); | ||
log.info('[options] Start options refresh'); | ||
await loadOptions(); | ||
log.info(`[options] ${options.length} options reloaded`); | ||
log.info('[options] End options refresh'); | ||
} catch (e: any) { | ||
log.error(`[graphql] options, ${JSON.stringify(e)}`); | ||
capture(e, { args }); | ||
return Promise.reject(new Error('request failed')); | ||
capture(e); | ||
log.error(`[options] failed to refresh options, ${JSON.stringify(e)}`); | ||
} | ||
await snapshot.utils.sleep(RUN_INTERVAL); | ||
run(); | ||
} | ||
|
||
run(); |