@@ -1016,6 +1016,44 @@ class Jobs {
10161016 return slims ;
10171017 }
10181018
1019+ updateJobLate ( updates ) {
1020+ // perform late update on job that may have already completed
1021+ var self = this ;
1022+
1023+ this . logJob ( 5 , "Attempting late update on completed job: " + updates . id , this . debugLevel ( 9 ) ? updates : false ) ;
1024+
1025+ this . unbase . update ( 'jobs' , updates . id , function ( job ) {
1026+ // perform updates here or bail out (inside unbase lock block)
1027+ if ( job . code == 'abort' ) {
1028+ updates . code = 'warning' ;
1029+ updates . description = 'Job was aborted, but received late update after completion.' ;
1030+ }
1031+
1032+ // append to job meta log
1033+ job . activity . push ( {
1034+ id : Tools . generateShortID ( 'm' ) ,
1035+ epoch : Tools . timeNow ( ) ,
1036+ server : 'm:' + self . hostID ,
1037+ msg : "WARNING: Received final job update post-completion."
1038+ } ) ;
1039+ updates . activity = job . activity ;
1040+
1041+ return updates ;
1042+ } ,
1043+ function ( err , job ) {
1044+ // done with update (and unlocked)
1045+ if ( err && ( err === "ABORT" ) ) return ; // update was aborted and callback was handled
1046+
1047+ if ( err ) {
1048+ self . logError ( 'job' , "Failed to update job late: " + updates . id + ": " + err ) ;
1049+ return ;
1050+ }
1051+
1052+ // refresh anyone sitting on job details page
1053+ self . doPageBroadcast ( 'Job?id=' + updates . id , 'job_completed' , { } ) ;
1054+ } ) ; // unbase.update
1055+ }
1056+
10191057 updateJobData ( socket , data ) {
10201058 // receive job update from satellite
10211059 // may contain multiple jobs, and apply updates as shallow merges to each
@@ -1035,8 +1073,9 @@ class Jobs {
10351073 var job = self . activeJobs [ job_id ] ;
10361074 var info = self . jobDetails [ job_id ] ;
10371075 if ( ! job || ! info ) {
1038- // should never happen, sanity check
1039- self . logJob ( 9 , "Job not found, updates not applied: " + job_id , updates ) ;
1076+ // can theoretically happen if a job timed out and the server came back
1077+ if ( updates . state == 'complete' ) self . updateJobLate ( updates ) ;
1078+ else self . logJob ( 9 , "Job not found, updates not applied: " + job_id , updates ) ;
10401079 return ;
10411080 }
10421081 if ( job . state == 'complete' ) {
0 commit comments