@@ -10,6 +10,8 @@ import fastifySession from "@fastify/session";
10
10
import { getSessionSecret , isCookieSecure } from "./utils/session" ;
11
11
import swagger from "@fastify/swagger" ;
12
12
import swaggerUi from "@fastify/swagger-ui" ;
13
+ import { pathToFileURL } from "url" ;
14
+ import { Worker } from "bullmq" ;
13
15
declare module "fastify" {
14
16
interface Session {
15
17
is_bot_allowed : boolean ;
@@ -82,5 +84,33 @@ const app: FastifyPluginAsync<AppOptions> = async (
82
84
} ) ;
83
85
} ;
84
86
87
+ const redis_url = process . env . DB_REDIS_URL || process . env . REDIS_URL ;
88
+ if ( ! redis_url ) {
89
+ throw new Error ( "Redis url is not defined" ) ;
90
+ }
91
+ const username = redis_url . split ( ":" ) [ 1 ] . replace ( "//" , "" ) ;
92
+ const password = redis_url . split ( ":" ) [ 2 ] . split ( "@" ) [ 0 ] ;
93
+ const host = redis_url . split ( "@" ) [ 1 ] . split ( ":" ) [ 0 ] ;
94
+ const port = parseInt ( redis_url . split ( ":" ) [ 3 ] ) ;
95
+ const path = join ( __dirname , "./queue/index.js" ) ;
96
+ const workerUrl = pathToFileURL ( path ) ;
97
+ const concurrency = parseInt ( process . env . DB_QUEUE_CONCURRENCY || "1" ) ;
98
+ const workerThreads = process . env . DB_QUEUE_THREADS || "false" ;
99
+ const worker = new Worker ( "vector" , workerUrl , {
100
+ connection : {
101
+ host,
102
+ port,
103
+ password,
104
+ username,
105
+ } ,
106
+ concurrency,
107
+ useWorkerThreads : workerThreads === "true" ,
108
+ } ) ;
109
+
110
+ process . on ( "SIGINT" , async ( ) => {
111
+ await worker . close ( ) ;
112
+ process . exit ( ) ;
113
+ } ) ;
114
+
85
115
export default app ;
86
116
export { app , options } ;
0 commit comments