@@ -73,21 +73,21 @@ Batch = function(options, run) {
73
73
this . out ( 'Starting ' + this . name + ' batch..' , 1 ) ;
74
74
75
75
try {
76
- total = db [ this . options . collection ] . count ( this . options . conditions ) ;
76
+ this . total = db [ this . options . collection ] . count ( this . options . conditions ) ;
77
77
} catch ( err ) {
78
78
this . out ( err . message , 1 ) ;
79
79
return false ;
80
80
}
81
81
82
- this . out ( 'Found ' + total + ' rows in ' + this . options . collection + ' to process' , 1 ) ;
82
+ this . out ( 'Found ' + this . total + ' rows in ' + this . options . collection + ' to process' , 1 ) ;
83
83
84
- if ( ! total ) {
84
+ if ( ! this . total ) {
85
85
return true ;
86
86
}
87
87
88
88
if ( ! this . options . step ) {
89
- if ( total > 10000 ) {
90
- this . options . step = Math . pow ( 10 , total . toString ( ) . length - 3 ) ;
89
+ if ( this . total > 10000 ) {
90
+ this . options . step = Math . pow ( 10 , this . total . toString ( ) . length - 3 ) ;
91
91
} else {
92
92
this . options . step = 100 ;
93
93
}
@@ -105,7 +105,7 @@ Batch = function(options, run) {
105
105
* @return void.
106
106
*/
107
107
this . finish = function ( ) {
108
- this . out ( 'Found ' + total + ' rows in ' + this . options . collection + ' to process' , 3 ) ;
108
+ this . out ( 'Found ' + this . total + ' rows in ' + this . options . collection + ' to process' , 3 ) ;
109
109
this . out ( 'All finished' , 1 ) ;
110
110
}
111
111
@@ -185,7 +185,7 @@ Batch = function(options, run) {
185
185
* @return void.
186
186
*/
187
187
this . processCursors = function ( ) {
188
- while ( this . processed < total || total === true ) {
188
+ while ( this . processed < this . total || this . total === true ) {
189
189
if ( ! this . processCursor ( ) ) {
190
190
this . out ( 'Last slice failed - aborting further processing in processCursors' , 4 ) ;
191
191
return ;
@@ -205,7 +205,7 @@ Batch = function(options, run) {
205
205
this . run = function ( ) {
206
206
this . startTime = new Date ( ) . getTime ( ) ;
207
207
this . processed = 0 ;
208
- this . total = 0 ;
208
+ this . total = this . options . total || 0 ;
209
209
this . currentRow = null ;
210
210
211
211
if ( ! this . start ( ) ) {
0 commit comments