@@ -2,10 +2,24 @@ const { processJob } = require("../controllers/job")
2
2
const { compileLog } = require ( "../utils/base" )
3
3
4
4
const Queue = require ( "bull" )
5
+ const redisUrlParse = require ( "redis-url-parse" )
5
6
6
7
// Connect to a local redis instance locally, and the Heroku-provided URL in production
7
8
const REDIS_URL = process . env . REDIS_URL || "redis://compile_queue:6379"
8
-
9
+ const { host, port, password } = redisUrlParse ( REDIS_URL )
10
+ const bullOptions = REDIS_URL . includes ( "rediss://" )
11
+ ? {
12
+ redis : {
13
+ port : Number ( port ) ,
14
+ host,
15
+ password,
16
+ tls : {
17
+ rejectUnauthorized : false ,
18
+ requestCert : true ,
19
+ } ,
20
+ } ,
21
+ }
22
+ : REDIS_URL
9
23
// The maximum number of jobs each worker should process at once
10
24
// Each job is CPU-intensive, so this value should not be too high
11
25
const maxJobsPerWorker = process . env . JOB_CONCURRENCY || 1
@@ -20,9 +34,7 @@ module.exports.start = id => {
20
34
compileLog ( `Started worker ${ id } ` )
21
35
22
36
// Connect to the named queue
23
- const compile_queue = new Queue ( "submissions" , REDIS_URL , {
24
- redis : { tls : { rejectUnauthorized : false , requestCert : true } } ,
25
- } )
37
+ const compile_queue = new Queue ( "submissions" , bullOptions )
26
38
27
39
// start processing jobs from the submission queue
28
40
compile_queue . process ( maxJobsPerWorker , processJob )
0 commit comments