egg_server/schedule/accessToken.ts
2024-11-25 11:08:54 +00:00

31 lines
797 B
TypeScript

import logger from "@egg/logger"
import { LarkService } from "@egg/net-tool"
import pLimit from "p-limit"
import db from "../db"
export const resetAccessToken = async () => {
try {
const appList = await db.appInfo.getFullList()
const limit = pLimit(3)
const promiseList = appList.map((app) =>
limit(() =>
new LarkService({
appId: app.app_id,
appSecret: app.app_secret,
requestId: "schedule",
}).auth
.getAppAuth()
.then((res) => {
return db.tenantAccessToken.update(app.id, app.name, res)
})
)
)
await Promise.allSettled(promiseList)
} catch (error: any) {
logger
.child({ requestId: "schedule" })
.error(`resetAccessToken error: ${error.message}`)
}
}