Skip to content

Commit

Permalink
fix redis 4 (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelxk authored Sep 28, 2022
1 parent b041484 commit 9b6d764
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions compile/src/handlers/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@ const { processJob } = require("../controllers/job")
const { compileLog } = require("../utils/base")

const Queue = require("bull")
const redisUrlParse = require("redis-url-parse")

// Connect to a local redis instance locally, and the Heroku-provided URL in production
const REDIS_URL = process.env.REDIS_URL || "redis://compile_queue:6379"

const { host, port, password } = redisUrlParse(REDIS_URL)
const bullOptions = REDIS_URL.includes("rediss://")
? {
redis: {
port: Number(port),
host,
password,
tls: {
rejectUnauthorized: false,
requestCert: true,
},
},
}
: REDIS_URL
// The maximum number of jobs each worker should process at once
// Each job is CPU-intensive, so this value should not be too high
const maxJobsPerWorker = process.env.JOB_CONCURRENCY || 1
Expand All @@ -20,9 +34,7 @@ module.exports.start = id => {
compileLog(`Started worker ${id}`)

// Connect to the named queue
const compile_queue = new Queue("submissions", REDIS_URL, {
redis: { tls: { rejectUnauthorized: false, requestCert: true } },
})
const compile_queue = new Queue("submissions", bullOptions)

// start processing jobs from the submission queue
compile_queue.process(maxJobsPerWorker, processJob)
Expand Down

0 comments on commit 9b6d764

Please sign in to comment.