Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Query redshift cluster using NodeJs asynchronously

My task is to copy few redshift tables from cluster one to a new cluster. For this I am writing a script in nodejs. I am using aws-sdk RedshiftData api to fetch the data. I have two separate queries which I want to run in parallel. Following is my code

class syncRedShiftNodes {
    
    constructor(){ ... }
    
    readDataOne(){
        let newSqlQuery = `select * from ${this.tableName} limit 10`;
        const params = {
          ClusterIdentifier: clusterIdentifier,
          Sql: newSqlQuery,
          Database: database,
          DbUser: dbUser
      };
      return new Promise((resolve, reject)=>{
        return awsRedshift.executeStatement(params, function(err, res){
                if (err) console.log(err, err.stack); // an error occurred
                else{
                    return awsRedshift.getStatementResult({Id:res.Id}, function(error, data){
                        if (error) console.log(error, error.stack); // an error occurred
                        else  return data;
                    });
                }
            });
      });
    }

   readDataTwo(){ ...//identical to above function except the query }

   main(){
       return Promise.all([this.readDataOne(), this.readDataTwo()])
         .spread((data1, data2)=>{
            console.log("promise resolved!!");
            return true;
   }
}

The problem is that my code is never reaching the "promise resolved" log. If I put a log in the callback of the redshift getStatementResult, that is being printed correctly but my handle is never reaching the promise.all().then statement which I am not able to understand why so.

Another question I had in mind was is it a good practice to use such a pattern inside a class?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You didn't resolve or reject your promise inside the class.

Example below

class syncRedShiftNodes {
  constructor() {}

  readDataOne() {
    let newSqlQuery = `select * from ${this.tableName} limit 10`;
    const params = {
      ClusterIdentifier: clusterIdentifier,
      Sql: newSqlQuery,
      Database: database,
      DbUser: dbUser,
    };
    return new Promise((resolve, reject) => {
      awsRedshift.executeStatement(params, function (err, res) {
        if (err) {
          console.log(err, err.stack);
          reject(err);
        } else {
          awsRedshift.getStatementResult(
            { Id: res.Id },
            function (error, data) {
              if (error) {
                console.log(error, error.stack);
                reject(error);
              } else {
                resolve(data);
              }
            }
          );
        }
      });
    });
  }

  readDataTwo() {}

  async main() {
    try {
      const result = await Promise.all([
        this.readDataOne(),
        this.readDataTwo(),
      ]);
      return result;
    } catch (err) {
      console.log(err);
    }
  }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!