Reputation: 1
I'm trying to get example code for a nodejs application using bull running in codesandbox working but struggling to get the application to connect to its redis backend, getting a message Error: MaxRetriesPerRequestError: Reached the max retries per request limit (which is 20).
The node app is copied from a helpful tutorial on medium by Shreshth Bansal: consists of
worker
const helloQueue = require('./queue');
// Function to process the task
async function printHelloWorld(job) {
// Simulating a task that takes 5 seconds to complete
setTimeout(() => {
console.log("Hello, world!");
}, 5000);
}
// Process jobs in the queue
helloQueue.process(async (job) => {
await printHelloWorld(job);
});
queue
const Bull = require('bull');
const helloQueue = new Bull('hello', {
redis: {
port: 6379,
host: '127.0.0.1',
},
});
module.exports = helloQueue;
api
const express = require('express');
const helloQueue = require('./queue');
const app = express();
const port = 3000;
// Endpoint to trigger the background task
app.get('/hello', async (req, res) => {
try {
// Add a job to the queue
await helloQueue.add({});
res.status(200).json({ message: 'Success' });
} catch (err) {
console.error('Error:', err);
res.status(500).json({ error: 'Internal server error' });
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
I followed instructions on how to install redis in a docker container and verified it's running (in a separate container). In this instruction there is no password protection and ports are 0.0.0.0:6379.
Is it better to run the redis backend in the same or separate container - any advice and what's the best way for a sandbox user to add/connect to Redis?
I've tried a couple of potential fixes based on other posted questions:
tls: true enableTLSForSentinelMode:false
added to redis options objected in bull queue, which haven't worked.
While I've used codesandbox quite a bit for node/react applications I have not had much experience/need to add services like redis or diverge from provided templates, nor am I experienced with Docker/containers and the nitty gritty of connecting between containerised services and apps.
Upvotes: 0
Views: 84