0

I want to insert infos from JIRA to a Sql Server, The JIRA server restrict me on the number of request I send in parallel so I have to dilute the number of call I can send in the same time.

I did it this way first and it works :

    mainJira.getAllPendingIssue(totalIssues).then(function(issues){
      var pendingTicket = mainJira.pop_to_array(issues)

      JiraToSql(pendingTicket,0,100)
      .then(
        JiraToSql(pendingTicket,100,200))
      .then(
        JiraToSql(pendingTicket,200,300))
    })

But as the number of issues may vary, I would like to do it in a loop. I tried this way but it doesn't work

      mainJira.getAllPendingIssue(totalIssues).then(function(issues){
        var pendingTicket = mainJira.pop_to_array(issues)
        for (pas = 0; pas < totalIssues; pas+= 50 ){
          console.log('pas : ',pas );        
          JiraToSql(pendingTicket,pas,pas + 50);
          } 
        })    
      })
Stakha
  • 61
  • 7
  • Possible duplicate of [Resolve promises one after another (i.e. in sequence)?](https://stackoverflow.com/questions/24586110/resolve-promises-one-after-another-i-e-in-sequence) – Jordan Running Apr 01 '19 at 16:59

1 Answers1

0

use array.forEach() on the result of your getAllPendingIssue() function call

mainJira.getAllPendingIssue(totalIssues).then(function(issues){
      var pendingTicket = mainJira.pop_to_array(issues);
      pendingTicket.forEach(function(issue){
           modifiedJiraToSQL(issue); 
      });

Note: about the modifiedJiraToSQL() function, you need to base this on your JiraToSQL() function to handle only one issue at a time.

Ian Preglo
  • 421
  • 2
  • 10