Wednesday, 10 May 2017

Mssql - Pause/Resume streaming request(NodeJs)

framework: NodeJs
database: Sql Server
Driver ms sql server for nodejs: mssql

I fetch n millions records from SqlServer (streaming) and process over every record. I want call nested functions into request.on('row', row => { }) and pause streaming until end of latest nested functions.

I want this:

const sql = require('mssql')

sql.connect(config, err => {
    // ... error checks 

    const request = new sql.Request()
    request.stream = true // You can set streaming differently for each request 
    request.query('select * from verylargetable') // or request.execute(procedure) 

    request.on('recordset', columns => {
        // Emitted once for each recordset in a query 
    })

    request.on('row', row => {
        // Emitted for each row in a recordset 
        //call process_1(row)
    })

    request.on('error', err => {
        // May be emitted multiple times 
    })

    request.on('done', result => {
        // Always emitted as the last one 
    })
})

sql.on('error', err => {
    // ... error handler 
})

function process_1(data){
    //process done after n minutes
   //if end process, then call process_2(newData)
}
function process_2(newData){
    //process done after n minutes
   //if end process, then resume streaming request
}

Notice: I read #181 and other issue about pause/pesume stream request, but I didn't get any idea! thanks



via Hossein Ganjyar

No comments:

Post a Comment