@@ -39,16 +39,17 @@ public void Any(FailJob request)
39
39
} ) ;
40
40
}
41
41
42
- public object Any ( RestoreModelQueues request )
42
+ public async Task < object > Any ( RestoreModelQueues request )
43
43
{
44
44
var pendingJobs = workerQueues . GetAll ( ) ;
45
45
var pendingJobIds = pendingJobs . Select ( x => x . Id ) . ToSet ( ) ;
46
- var incompleteJobs = Db . Select ( Db . From < PostJob > ( ) . Where ( x => x . CompletedDate == null ) ) ;
46
+ var incompleteJobs = await Db . SelectAsync ( Db . From < PostJob > ( ) . Where ( x => x . CompletedDate == null ) ) ;
47
47
var missingJobs = incompleteJobs . Where ( x => ! pendingJobIds . Contains ( x . Id ) && x . StartedDate == null ) . ToList ( ) ;
48
48
var startedJobs = incompleteJobs . Where ( x => x . StartedDate != null ) . ToList ( ) ;
49
49
var lostJobsBefore = DateTime . UtcNow . Add ( TimeSpan . FromMinutes ( - 5 ) ) ;
50
50
var lostJobs = startedJobs . Where ( x => x . StartedDate < lostJobsBefore && missingJobs . All ( m => m . Id != x . Id ) ) . ToList ( ) ;
51
- var failedJobsCount = Db . Count ( Db . From < PostJob > ( ) . Where ( x => x . CompletedDate != null && x . Error != null ) ) ;
51
+ var failedJobs = await Db . SelectAsync ( Db . From < PostJob > ( ) . Where ( x => x . CompletedDate != null && x . Error != null ) ) ;
52
+ var restoreFailedJobs = request . RestoreFailedJobs == true ;
52
53
53
54
foreach ( var lostJob in lostJobs )
54
55
{
@@ -58,6 +59,11 @@ public object Any(RestoreModelQueues request)
58
59
{
59
60
workerQueues . Enqueue ( missingJob ) ;
60
61
}
62
+ foreach ( var failedJob in failedJobs )
63
+ {
64
+ workerQueues . Enqueue ( failedJob ) ;
65
+ }
66
+ var failedSuffix = restoreFailedJobs ? ", restored!" : "" ;
61
67
62
68
return new StringsResponse
63
69
{
@@ -66,7 +72,7 @@ public object Any(RestoreModelQueues request)
66
72
$ "{ incompleteJobs . Count } incomplete jobs in database",
67
73
$ "{ startedJobs . Count } jobs being processed by workers",
68
74
$ "{ missingJobs . Count } missing and { lostJobs . Count } lost jobs re-added to queue",
69
- $ "{ failedJobsCount } failed jobs",
75
+ $ "{ failedJobs . Count } failed jobs{ failedSuffix } ",
70
76
]
71
77
} ;
72
78
}
0 commit comments