@@ -39,81 +39,81 @@ var assign = require('lodash.assign');
3939 * Finished; returning exit code 0
4040 */
4141
42- function parseLogs ( data , allLogs , json ) {
43- var line = 0 ;
44- var eof = false ;
45- if ( data . length ) {
46- data . forEach ( function itemFunc ( item ) {
47- if ( typeof item . message === 'string' ) {
48- if ( item . message . endsWith ( '\r' ) ) item . message = item . message . slice ( 0 , - 1 ) ;
49- if ( item . message === 'PSEOF' ) eof = true ;
50- if ( item . line ) line = item . line ;
51- if ( global . paperspace_cli && ! json && ! eof ) {
52- console . log ( item . message ) ;
53- } else if ( allLogs ) allLogs . push ( item ) ;
54- } else if ( item . line ) line = item . line ;
55- } ) ;
56- }
57- return { count : data . length + 0 , line : line , eof : eof } ;
58- }
42+ function parseLogs ( data , allLogs , json ) {
43+ var line = 0 ;
44+ var eof = false ;
45+ if ( data . length ) {
46+ data . forEach ( function itemFunc ( item ) {
47+ if ( typeof item . message === 'string' ) {
48+ if ( item . message . endsWith ( '\r' ) ) item . message = item . message . slice ( 0 , - 1 ) ;
49+ if ( item . message === 'PSEOF' ) eof = true ;
50+ if ( item . line ) line = item . line ;
51+ if ( global . paperspace_cli && ! json && ! eof ) {
52+ console . log ( item . message ) ;
53+ } else if ( allLogs ) allLogs . push ( item ) ;
54+ } else if ( item . line ) line = item . line ;
55+ } ) ;
56+ }
57+ return { count : data . length + 0 , line : line , eof : eof } ;
58+ }
5959
6060function logs ( params , cb ) {
61- params . jobId = projectConfig . getLastJobId ( null , params . jobId ) ;
61+ params . jobId = projectConfig . getLastJobId ( null , params . jobId ) ;
6262 var tail = false ;
6363 if ( params . tail ) {
6464 tail = true ;
6565 delete params . tail ;
6666 }
67- var json = false ;
67+ var json = false ;
6868 if ( params . json ) {
6969 json = true ;
7070 delete params . json ;
7171 }
72- var singleChunk = false ;
72+ var singleChunk = false ;
7373 if ( typeof params . line === 'undefined' ) params . line = 0 ;
74- else singleChunk = true ; // if line is specified only a limited chunk will be returned; params.limit defines the limit; default is 2000
75- var backoff = 0 ;
76- var allLogs ;
77- if ( ! global . paperspace_cli || json ) allLogs = [ ] ;
74+ else singleChunk = true ; // if line is specified only a limited chunk will be returned; params.limit defines the limit; default is 2000
75+ var backoff = 0 ;
76+ var allLogs ;
77+ if ( ! global . paperspace_cli || json ) allLogs = [ ] ;
7878
79- var MAX_BACKOFF_SECS = 30 ;
79+ var MAX_BACKOFF_SECS = 30 ;
8080
81- function _logs ( ) {
82- return method ( logs , params , function logsCb ( err , data ) {
83- if ( err ) cb ( err ) ;
84- var result = parseLogs ( data , allLogs , json ) ;
85- if ( result . count > 0 ) {
86- // store new last line in method params
87- params . line = result . line ;
88- }
89- if ( ( result . count > 0 || tail ) && ! result . eof && ! singleChunk ) {
90- if ( result . count > 0 ) backoff = 0 ;
91- else if ( backoff < MAX_BACKOFF_SECS ) {
92- // increase backoff geometrically
93- if ( backoff === 0 ) backoff = 1 ;
94- else backoff *= 2 ;
95- }
96- else backoff = MAX_BACKOFF_SECS ; // cap backoff at this
81+ function _logs ( ) {
82+ return method ( logs , params , function logsCb ( err , data ) {
83+ if ( err ) cb ( err ) ;
84+ var result = parseLogs ( data , allLogs , json ) ;
85+ if ( result . count > 0 ) {
86+ // store new last line in method params
87+ params . line = result . line ;
88+ }
89+ if ( ( result . count > 0 || tail ) && ! result . eof && ! singleChunk ) {
90+ if ( result . count > 0 ) backoff = 0 ;
91+ else if ( backoff < MAX_BACKOFF_SECS ) {
92+ // increase backoff geometrically
93+ if ( backoff === 0 ) backoff = 1 ;
94+ else backoff *= 2 ;
95+ }
96+ else backoff = MAX_BACKOFF_SECS ; // cap backoff at this
9797
98- if ( backoff > 0 ) {
99- // sleep for backoff secs then query logs again
100- return setTimeout ( function _interval ( ) {
101- return _logs ( ) ;
102- } , backoff * 1000 ) ;
103- }
104- else {
105- // querey logs immediately
106- return _logs ( ) ;
107- }
108- }
109- if ( global . paperspace_cli && ! json ) {
110- return cb ( ) ;
111- }
112- return cb ( null , allLogs ) ;
113- } ) ;
114- }
98+ if ( backoff > 0 ) {
99+ // sleep for backoff secs then query logs again
100+ return setTimeout ( function _interval ( ) {
101+ return _logs ( ) ;
102+ } , backoff * 1000 ) ;
103+ }
104+ else {
105+ // querey logs immediately
106+ return _logs ( ) ;
107+ }
108+ }
109+ if ( global . paperspace_cli && ! json ) {
110+ return cb ( ) ;
111+ }
112+ return cb ( null , allLogs ) ;
113+ } ) ;
114+ }
115115
116- return _logs ( ) ;
116+ return _logs ( ) ;
117117}
118118
119119
0 commit comments