import { withTaskCore } from "./core"; import { listPlaysExpired, terminatePlay } from "../stores"; import * as akashicModule from "../modules/akashic"; export default withTaskCore((core) => { return async () => { const firestore = core.getFirestore(); const logger = core.getLogger(); const config = await core.getConfig(); const now = new Date(); const akashicClient = akashicModule.createWrapper({ mode: config.akashic.mode, baseUrl: config.akashic.baseUrl, apiKey: config.akashic.apiKey, refreshToken: config.akashic.refreshToken, refreshTokenUrl: config.akashic.refreshTokenUrl, firestore: firestore, }); const plays = await listPlaysExpired(firestore, now); if (plays.length === 0) return; logger.info(`期限切れのPlayが ${plays.length} 件見つかりました。`, { task: "CheckExpiredPlays", }); for (const play of plays) { if (play.akashicPlayId != null) { await akashicClient.stopInstance(play.akashicPlayId); } await terminatePlay(firestore, play.id); } return; }; });