Stop bree and cloudflared while the server shutting down

This commit is contained in:
Louis Lam
2022-04-05 19:41:29 +08:00
parent d8b32d652f
commit 48d679234a
3 changed files with 22 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
const path = require("path");
const Bree = require("bree");
const { SHARE_ENV } = require("worker_threads");
let bree;
const jobs = [
{
name: "clear-old-data",
@@ -10,7 +10,7 @@ const jobs = [
];
const initBackgroundJobs = function (args) {
const bree = new Bree({
bree = new Bree({
root: path.resolve("server", "jobs"),
jobs,
worker: {
@@ -26,6 +26,13 @@ const initBackgroundJobs = function (args) {
return bree;
};
module.exports = {
initBackgroundJobs
const stopBackgroundJobs = function () {
if (bree) {
bree.stop();
}
};
module.exports = {
initBackgroundJobs,
stopBackgroundJobs
};