Skip to content

Commit

Permalink
automate search updates
Browse files Browse the repository at this point in the history
  • Loading branch information
0xngmi committed Aug 28, 2024
1 parent 8a1f868 commit 27f99b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
6 changes: 6 additions & 0 deletions defi/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ functions:
memorySize: 512
events:
- schedule: cron(20 * * * ? *)
updateSearch:
handler: src/updateSearch.default
timeout: 900
memorySize: 512
events:
- schedule: cron(30 * * * ? *)
# missedUpdates:
# handler: src/stats/getMissedUpdates.default
# timeout: 30
Expand Down
30 changes: 23 additions & 7 deletions defi/src/cli/search/generate.ts → defi/src/updateSearch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { writeFile as writeFileRaw } from "fs"
import { promisify } from "util"
import {sluggifyString} from "../../utils/sluggify"
const writeFile = promisify(writeFileRaw)
import {sluggifyString} from "./utils/sluggify"

const normalize = (str:string) => sluggifyString(str).replace(/[^a-zA-Z0-9_-]/, "").replace(/[^a-zA-Z0-9_-]/, "").replace(/[^a-zA-Z0-9_-]/, "")
const standardizeProtocolName = (tokenName = '') =>
tokenName?.toLowerCase().split(' ').join('-').split("'").join('')

async function main() {
async function generateSearchList() {
const protocols:{
chains: string[],
parentProtocols: any[],
Expand Down Expand Up @@ -59,6 +56,25 @@ async function main() {
tvl: categoryTvl[category],
url: `/protocols/${category}`
})))
await writeFile("./searchProtocols.json", JSON.stringify(results))
return results
}
main()

export default async ()=>{
const searchResults = await generateSearchList()
const submit = await fetch(`https://search.defillama.com/indexes/protocols/documents`, {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SEARCH_MASTER_KEY}`
},
body: JSON.stringify(searchResults)
}).then(r=>r.json())
const status = await fetch(`https://search.defillama.com/tasks/${submit.taskUid}`, {
headers: {
"Authorization": `Bearer ${process.env.SEARCH_MASTER_KEY}`
},
}).then(r=>r.json())
const errorMessage = status?.details?.error?.message
if(errorMessage){
console.log(errorMessage)
}
}

0 comments on commit 27f99b5

Please sign in to comment.