-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Graceful shutdown: wait for session to be released (#35)
* Graceful shutdown: wait for session to be released * Disable puppeteer signal handling, remove hacks around it * Reset session info on release as it is implicitly restarted * Re-introduce signal handler removal for local dev env `npm run dev` will install its own signal handlers and break things
- Loading branch information
Showing
14 changed files
with
240 additions
and
120 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,4 +1,4 @@ | ||
ARG NODE_VERSION=20.12.0 | ||
ARG NODE_VERSION=22.13.0 | ||
|
||
FROM node:${NODE_VERSION}-slim AS base | ||
|
||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import fastifyGracefulShutdown from "fastify-graceful-shutdown"; | ||
import { FastifyPluginAsync } from "fastify"; | ||
import fp from "fastify-plugin"; | ||
import { SessionService } from "../services/session.service"; | ||
import { env } from "../env"; | ||
|
||
const browserSessionPlugin: FastifyPluginAsync = async (fastify, options) => { | ||
const sessionService = new SessionService({ | ||
cdpService: fastify.cdpService, | ||
seleniumService: fastify.seleniumService, | ||
logger: fastify.log, | ||
}); | ||
fastify.decorate("sessionService", sessionService); | ||
|
||
process.removeAllListeners("SIGINT"); | ||
process.removeAllListeners("SIGTERM"); | ||
|
||
const gracefulOptions = { | ||
timeout: parseInt(env.KILL_TIMEOUT) * 1000, | ||
}; | ||
fastify.register(fastifyGracefulShutdown, gracefulOptions).after((err) => { | ||
if (err) { | ||
fastify.log.error(err) | ||
} | ||
|
||
fastify.gracefulShutdown(async (_signal) => { | ||
if (sessionService.activeSession.status === "live") { | ||
fastify.log.info("Waiting for active session to be released..."); | ||
await sessionService.activeSession.completion; | ||
fastify.log.info("Active session has been released..."); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
export default fp(browserSessionPlugin, "4.x"); |
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
Oops, something went wrong.