Replies: 1 comment 8 replies
-
It looks like you want to schedule a job to delete a user when a specific API endpoint is hit, and you're using some kind of queueing mechanism to accomplish this. You'll need to modify the router.post handler to add the job to the queue with the required email parameter. Inside the worker, you'll need to extract the email parameter from the job data. Here's an example of how you can achieve this: // Define the endpoint that clients will POST to
router.post('/delete-user', (req, res) => {
const {email} = req.body;
// Schedule the job to delete the user by adding it to the queue
queue.add("myJob", { email }, { delay: 1000 });
res.send("Scheduled the job to delete user with email: " + email);
});
// Define the worker that will process the job
const worker = new Worker('myQueue', async (job) => {
// Extract the email from the job data
const email = job.data.email;
await hitApi(email);
}, {
connection: {
host: 'myhost.com',
port: 366,
password: 'pass'
},
delay: 5000
});
// Define other aspects of your code as you had before... This code snippet schedules a job with the user's email whenever the /delete-user endpoint is hit. Inside the worker function, the email is extracted from the job data, and the hitApi function is called with that email. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How do i schedule the job now as the hitApi function will need email as a parameter in order to run,
But if the email is coming from the body then How will things work?
I only want to schedule the job when the user hits the API
Beta Was this translation helpful? Give feedback.
All reactions