-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move pre-ready up to separate module
- Loading branch information
1 parent
2f85d55
commit 18b108c
Showing
19 changed files
with
149 additions
and
51 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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
import fp from 'fastify-plugin' | ||
import { cancel } from './cancel' | ||
import { isPreReadied } from './is-pre-readied' | ||
import { start } from './start' | ||
import { toggle } from './toggle' | ||
import { resolve } from 'node:path' | ||
|
||
export const preReady = { | ||
cancel, | ||
isPreReadied, | ||
start, | ||
toggle, | ||
} as const | ||
|
||
export default fp( | ||
async app => { | ||
await app.register((await import('@fastify/autoload')).default, { | ||
dir: resolve(import.meta.dirname, 'plugins'), | ||
}) | ||
}, | ||
{ name: 'pre-ready up' }, | ||
) |
4 changes: 2 additions & 2 deletions
4
src/queue/pre-ready/is-pre-readied.ts → src/pre-ready/is-pre-readied.ts
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,33 @@ | ||
import fp from 'fastify-plugin' | ||
import { collections } from '../../database/collections' | ||
import { update } from '../../players/update' | ||
import { secondsToMilliseconds } from 'date-fns' | ||
import { events } from '../../events' | ||
import { safe } from '../../utils/safe' | ||
|
||
async function process() { | ||
const toRemove = await collections.players.find({ preReadyUntil: { $lte: new Date() } }).toArray() | ||
for (const p of toRemove) { | ||
await update(p.steamId, { $unset: { preReadyUntil: 1 } }) | ||
} | ||
} | ||
|
||
export default fp( | ||
async () => { | ||
setInterval(process, secondsToMilliseconds(1)) | ||
|
||
events.on( | ||
'game:created', | ||
safe(async ({ game }) => { | ||
await Promise.all( | ||
game.slots.map( | ||
async ({ player }) => await update(player, { $unset: { preReadyUntil: 1 } }), | ||
), | ||
) | ||
}), | ||
) | ||
}, | ||
{ | ||
name: 'auto cancel pre-ready up', | ||
}, | ||
) |
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
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