1010
1111use OCA \Libresign \BackgroundJob \SignFileJob ;
1212use OCA \Libresign \BackgroundJob \SignSingleFileJob ;
13+ use OCA \Libresign \Service \Process \ProcessManager ;
14+ use OCA \Libresign \Vendor \Symfony \Component \Process \Process ;
1315use OCP \IBinaryFinder ;
1416
1517class WorkerStarter {
1618 private const MAX_WORKERS = 32 ;
19+ private const PROCESS_SOURCE = 'worker ' ;
1720
1821 public function __construct (
1922 private IBinaryFinder $ binaryFinder ,
23+ private ProcessManager $ processManager ,
2024 ) {
2125 }
2226
@@ -41,13 +45,25 @@ private function clampWorkerCount(int $count): int {
4145 }
4246
4347 private function executeCommand (string $ phpPath , string $ occPath , array $ jobClasses ): void {
44- $ jobClassesArg = implode (' ' , array_map ('escapeshellarg ' , $ jobClasses ));
45- $ cmd = sprintf (
46- '%s %s background-job:worker %s --stop_after=30m >> /dev/null 2>&1 & ' ,
47- escapeshellarg ($ phpPath ),
48- escapeshellarg ($ occPath ),
49- $ jobClassesArg
50- );
51- shell_exec ($ cmd );
48+ $ command = [
49+ $ phpPath ,
50+ $ occPath ,
51+ 'background-job:worker ' ,
52+ ...$ jobClasses ,
53+ '--stop_after=30m ' ,
54+ ];
55+ $ process = $ this ->createProcess ($ command );
56+ $ process ->setOptions (['create_new_console ' => true ]);
57+ $ process ->setTimeout (null );
58+ $ process ->start ();
59+
60+ $ pid = $ process ->getPid () ?? 0 ;
61+ if ($ pid > 0 ) {
62+ $ this ->processManager ->register (self ::PROCESS_SOURCE , $ pid );
63+ }
64+ }
65+
66+ protected function createProcess (array $ command ): Process {
67+ return new Process ($ command );
5268 }
5369}
0 commit comments