Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to force the execution happening in 1 pod/container in Openshift/Kubernetes #2313

Closed
chanlevan opened this issue Mar 2, 2022 · 0 comments

Comments

@chanlevan
Copy link

chanlevan commented Mar 2, 2022

Hi everyone,

I have a backend node application using 1 queue. Every REST request comes, I create 200 jobs and do some processing on each job. After the execution is done, the result of all jobs are logged into an excel file.

I deployed this application to Openshift(Kubernetes in the backend). It works perfectly with 1 pod. However, if I increase the number of pod more than 1, Kubernetes starts distribute the jobs to not only the first pod but also to different pods. I am wondering if anyone faces the same issue and knows the way how to force all of the jobs to be executed only in 1 pod using bull? Or if it the execution runs in multiple pods, what should be the proper way to catch the complete event after the execution of all jobs are done from multiple pods?
I attached my sample code as below.

Looking forward for some helps.
Chan.

import * as Queue from "bull";
import { myjob} from "./myjob.job";
const { NX_REDIS, NX_REDIS_PASSWORD, REDIS_PORT } = process.env;
let myQueue: Queue.Queue<any>;
const redisOptions = {
  port: REDIS_PORT ,
  host: NX_REDIS,
  password: NX_REDIS_PASSWORD 
};

const createQueueMQ = (name) => new Queue(name, { redis: redisOptions });
const activateQueue = async (queueName: string) => {
  myQueue.process((job) => {
    return Promise.resolve(myjob(job));
  });
  myQueue.on("error", (error) => {
    console.log(error);
  });
};
if (NX_REDIS) {
  myQueue= createQueueMQ("myqueue");
  activateQueue(myQueue.name);
}
export { myQueue };

export const addJobs = async (queryType: string, username: string) => {
  const filteredQueries: Array<any> = await getSQLqueries(
    queryType
  );
  const totalQueries: number = filteredQueries.length;
  let results: Array<any> = [];
  try {
    filteredQueries.forEach((query) => {
      myQueue.add(query);
    });
    myQueue.on("completed", (job, result) => {
      results.push(job.returnvalue);
      if (results.length === totalQueries) {
        generateExcelfile(results);
      }
    });
  } catch (error) {
    throw error;
  }
};
@OptimalBits OptimalBits locked and limited conversation to collaborators Mar 11, 2022
@manast manast converted this issue into discussion #2321 Mar 11, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant