1818use OCP \IConfig ;
1919use OCP \IServerInfo ;
2020use Override ;
21+ use Psr \Log \LoggerInterface ;
2122
2223class CleanupBackgroundJobsJob extends TimedJob {
2324 public function __construct (
@@ -28,7 +29,7 @@ public function __construct(
2829 ) {
2930 parent ::__construct ($ time );
3031 $ this ->setInterval (60 * 60 );
31- $ this ->setTimeSensitivity (IJob::TIME_INSENSITIVE );
32+ $ this ->setTimeSensitivity (IJob::TIME_SENSITIVE );
3233 }
3334
3435 #[Override]
@@ -45,17 +46,24 @@ private function reapCrashedJobs(): void {
4546 if ($ job ->serverId !== $ currentServerId ) {
4647 continue ;
4748 }
49+ $ output = [];
50+ $ result = 0 ;
4851 exec ('ps -p ' . escapeshellarg ((string )$ job ->pid ) . ' -o cmd ' , $ output , $ result );
49- if (count ($ output ) === 1 && $ output[ 0 ] === 'CMD ' && $ result === 1 ) {
52+ if (count ($ output ) === 1 && current ( $ output) === 'CMD ' && $ result === 1 ) {
5053 // Process doesn't exists anymore
5154 $ maxDuration = (new DateTimeImmutable ())->diff ($ job ->startedAt );
52- $ maxDuration =
53- ($ maxDuration ->format ( ' %a ' ) * 24 * 60 * 60 * 1000 )
54- + ($ maxDuration ->format ( ' %h ' ) * 60 * 60 * 1000 )
55- + ($ maxDuration ->format ( ' %m ' ) * 60 * 1000 )
56- + ($ maxDuration ->format ( ' %s ' ) * 1000 )
57- + (int )($ maxDuration ->format ( ' %f ' ) / 1000 );
55+ $ maxDuration
56+ = ($ maxDuration ->days * 24 * 60 * 60 * 1000 )
57+ + ($ maxDuration ->h * 60 * 60 * 1000 )
58+ + ($ maxDuration ->i * 60 * 1000 )
59+ + ($ maxDuration ->s * 1000 )
60+ + (int )($ maxDuration ->f * 1000 );
5861 $ this ->jobRuns ->finished ($ job ->runId , $ maxDuration , 0 , JobStatus::CRASHED );
62+ $ this ->logger ->warning ('No process matching PID {pid} found on server {serverId}. Job {runId} was marked as crashed ' , [
63+ 'pid ' => $ job ->pid ,
64+ 'serverId ' => $ job ->serverId ,
65+ 'runId ' => $ job ->runId ,
66+ ]);
5967 }
6068 }
6169 }
0 commit comments