Completed
Push — master ( 772471...e53395 )
by Christoph
30:52
created
core/Command/TaskProcessing/Statistics.php 2 patches
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -16,181 +16,181 @@
 block discarded – undo
16 16
 use Symfony\Component\Console\Output\OutputInterface;
17 17
 
18 18
 class Statistics extends Base {
19
-	public function __construct(
20
-		protected IManager $taskProcessingManager,
21
-	) {
22
-		parent::__construct();
23
-	}
19
+    public function __construct(
20
+        protected IManager $taskProcessingManager,
21
+    ) {
22
+        parent::__construct();
23
+    }
24 24
 
25
-	protected function configure() {
26
-		$this
27
-			->setName('taskprocessing:task:stats')
28
-			->setDescription('get statistics for tasks')
29
-			->addOption(
30
-				'userIdFilter',
31
-				'u',
32
-				InputOption::VALUE_OPTIONAL,
33
-				'only get the tasks for one user ID'
34
-			)
35
-			->addOption(
36
-				'type',
37
-				't',
38
-				InputOption::VALUE_OPTIONAL,
39
-				'only get the tasks for one task type'
40
-			)
41
-			->addOption(
42
-				'appId',
43
-				null,
44
-				InputOption::VALUE_OPTIONAL,
45
-				'only get the tasks for one app ID'
46
-			)
47
-			->addOption(
48
-				'customId',
49
-				null,
50
-				InputOption::VALUE_OPTIONAL,
51
-				'only get the tasks for one custom ID'
52
-			)
53
-			->addOption(
54
-				'status',
55
-				's',
56
-				InputOption::VALUE_OPTIONAL,
57
-				'only get the tasks that have a specific status (STATUS_UNKNOWN=0, STATUS_SCHEDULED=1, STATUS_RUNNING=2, STATUS_SUCCESSFUL=3, STATUS_FAILED=4, STATUS_CANCELLED=5)'
58
-			)
59
-			->addOption(
60
-				'scheduledAfter',
61
-				null,
62
-				InputOption::VALUE_OPTIONAL,
63
-				'only get the tasks that were scheduled after a specific date (Unix timestamp)'
64
-			)
65
-			->addOption(
66
-				'endedBefore',
67
-				null,
68
-				InputOption::VALUE_OPTIONAL,
69
-				'only get the tasks that ended before a specific date (Unix timestamp)'
70
-			);
71
-		parent::configure();
72
-	}
25
+    protected function configure() {
26
+        $this
27
+            ->setName('taskprocessing:task:stats')
28
+            ->setDescription('get statistics for tasks')
29
+            ->addOption(
30
+                'userIdFilter',
31
+                'u',
32
+                InputOption::VALUE_OPTIONAL,
33
+                'only get the tasks for one user ID'
34
+            )
35
+            ->addOption(
36
+                'type',
37
+                't',
38
+                InputOption::VALUE_OPTIONAL,
39
+                'only get the tasks for one task type'
40
+            )
41
+            ->addOption(
42
+                'appId',
43
+                null,
44
+                InputOption::VALUE_OPTIONAL,
45
+                'only get the tasks for one app ID'
46
+            )
47
+            ->addOption(
48
+                'customId',
49
+                null,
50
+                InputOption::VALUE_OPTIONAL,
51
+                'only get the tasks for one custom ID'
52
+            )
53
+            ->addOption(
54
+                'status',
55
+                's',
56
+                InputOption::VALUE_OPTIONAL,
57
+                'only get the tasks that have a specific status (STATUS_UNKNOWN=0, STATUS_SCHEDULED=1, STATUS_RUNNING=2, STATUS_SUCCESSFUL=3, STATUS_FAILED=4, STATUS_CANCELLED=5)'
58
+            )
59
+            ->addOption(
60
+                'scheduledAfter',
61
+                null,
62
+                InputOption::VALUE_OPTIONAL,
63
+                'only get the tasks that were scheduled after a specific date (Unix timestamp)'
64
+            )
65
+            ->addOption(
66
+                'endedBefore',
67
+                null,
68
+                InputOption::VALUE_OPTIONAL,
69
+                'only get the tasks that ended before a specific date (Unix timestamp)'
70
+            );
71
+        parent::configure();
72
+    }
73 73
 
74
-	protected function execute(InputInterface $input, OutputInterface $output): int {
75
-		$userIdFilter = $input->getOption('userIdFilter');
76
-		if ($userIdFilter === null) {
77
-			$userIdFilter = '';
78
-		} elseif ($userIdFilter === '') {
79
-			$userIdFilter = null;
80
-		}
81
-		$type = $input->getOption('type');
82
-		$appId = $input->getOption('appId');
83
-		$customId = $input->getOption('customId');
84
-		$status = $input->getOption('status') !== null ? (int)$input->getOption('status') : null;
85
-		$scheduledAfter = $input->getOption('scheduledAfter') !== null ? (int)$input->getOption('scheduledAfter') : null;
86
-		$endedBefore = $input->getOption('endedBefore') !== null ? (int)$input->getOption('endedBefore') : null;
74
+    protected function execute(InputInterface $input, OutputInterface $output): int {
75
+        $userIdFilter = $input->getOption('userIdFilter');
76
+        if ($userIdFilter === null) {
77
+            $userIdFilter = '';
78
+        } elseif ($userIdFilter === '') {
79
+            $userIdFilter = null;
80
+        }
81
+        $type = $input->getOption('type');
82
+        $appId = $input->getOption('appId');
83
+        $customId = $input->getOption('customId');
84
+        $status = $input->getOption('status') !== null ? (int)$input->getOption('status') : null;
85
+        $scheduledAfter = $input->getOption('scheduledAfter') !== null ? (int)$input->getOption('scheduledAfter') : null;
86
+        $endedBefore = $input->getOption('endedBefore') !== null ? (int)$input->getOption('endedBefore') : null;
87 87
 
88
-		$tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $appId, $customId, $status, $scheduledAfter, $endedBefore);
88
+        $tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $appId, $customId, $status, $scheduledAfter, $endedBefore);
89 89
 
90
-		$stats = ['Number of tasks' => count($tasks)];
90
+        $stats = ['Number of tasks' => count($tasks)];
91 91
 
92
-		$maxRunningTime = 0;
93
-		$totalRunningTime = 0;
94
-		$runningTimeCount = 0;
92
+        $maxRunningTime = 0;
93
+        $totalRunningTime = 0;
94
+        $runningTimeCount = 0;
95 95
 
96
-		$maxQueuingTime = 0;
97
-		$totalQueuingTime = 0;
98
-		$queuingTimeCount = 0;
96
+        $maxQueuingTime = 0;
97
+        $totalQueuingTime = 0;
98
+        $queuingTimeCount = 0;
99 99
 
100
-		$maxUserWaitingTime = 0;
101
-		$totalUserWaitingTime = 0;
102
-		$userWaitingTimeCount = 0;
100
+        $maxUserWaitingTime = 0;
101
+        $totalUserWaitingTime = 0;
102
+        $userWaitingTimeCount = 0;
103 103
 
104
-		$maxInputSize = 0;
105
-		$maxOutputSize = 0;
106
-		$inputCount = 0;
107
-		$inputSum = 0;
108
-		$outputCount = 0;
109
-		$outputSum = 0;
104
+        $maxInputSize = 0;
105
+        $maxOutputSize = 0;
106
+        $inputCount = 0;
107
+        $inputSum = 0;
108
+        $outputCount = 0;
109
+        $outputSum = 0;
110 110
 
111
-		foreach ($tasks as $task) {
112
-			// running time
113
-			if ($task->getStartedAt() !== null && $task->getEndedAt() !== null) {
114
-				$taskRunningTime = $task->getEndedAt() - $task->getStartedAt();
115
-				$totalRunningTime += $taskRunningTime;
116
-				$runningTimeCount++;
117
-				if ($taskRunningTime >= $maxRunningTime) {
118
-					$maxRunningTime = $taskRunningTime;
119
-				}
120
-			}
121
-			// queuing time
122
-			if ($task->getScheduledAt() !== null && $task->getStartedAt() !== null) {
123
-				$taskQueuingTime = $task->getStartedAt() - $task->getScheduledAt();
124
-				$totalQueuingTime += $taskQueuingTime;
125
-				$queuingTimeCount++;
126
-				if ($taskQueuingTime >= $maxQueuingTime) {
127
-					$maxQueuingTime = $taskQueuingTime;
128
-				}
129
-			}
130
-			// user waiting time
131
-			if ($task->getScheduledAt() !== null && $task->getEndedAt() !== null) {
132
-				$taskUserWaitingTime = $task->getEndedAt() - $task->getScheduledAt();
133
-				$totalUserWaitingTime += $taskUserWaitingTime;
134
-				$userWaitingTimeCount++;
135
-				if ($taskUserWaitingTime >= $maxUserWaitingTime) {
136
-					$maxUserWaitingTime = $taskUserWaitingTime;
137
-				}
138
-			}
139
-			// input/output sizes
140
-			if ($task->getStatus() === Task::STATUS_SUCCESSFUL) {
141
-				$outputString = json_encode($task->getOutput());
142
-				if ($outputString !== false) {
143
-					$outputCount++;
144
-					$outputLength = strlen($outputString);
145
-					$outputSum += $outputLength;
146
-					if ($outputLength > $maxOutputSize) {
147
-						$maxOutputSize = $outputLength;
148
-					}
149
-				}
150
-			}
151
-			$inputString = json_encode($task->getInput());
152
-			if ($inputString !== false) {
153
-				$inputCount++;
154
-				$inputLength = strlen($inputString);
155
-				$inputSum += $inputLength;
156
-				if ($inputLength > $maxInputSize) {
157
-					$maxInputSize = $inputLength;
158
-				}
159
-			}
160
-		}
111
+        foreach ($tasks as $task) {
112
+            // running time
113
+            if ($task->getStartedAt() !== null && $task->getEndedAt() !== null) {
114
+                $taskRunningTime = $task->getEndedAt() - $task->getStartedAt();
115
+                $totalRunningTime += $taskRunningTime;
116
+                $runningTimeCount++;
117
+                if ($taskRunningTime >= $maxRunningTime) {
118
+                    $maxRunningTime = $taskRunningTime;
119
+                }
120
+            }
121
+            // queuing time
122
+            if ($task->getScheduledAt() !== null && $task->getStartedAt() !== null) {
123
+                $taskQueuingTime = $task->getStartedAt() - $task->getScheduledAt();
124
+                $totalQueuingTime += $taskQueuingTime;
125
+                $queuingTimeCount++;
126
+                if ($taskQueuingTime >= $maxQueuingTime) {
127
+                    $maxQueuingTime = $taskQueuingTime;
128
+                }
129
+            }
130
+            // user waiting time
131
+            if ($task->getScheduledAt() !== null && $task->getEndedAt() !== null) {
132
+                $taskUserWaitingTime = $task->getEndedAt() - $task->getScheduledAt();
133
+                $totalUserWaitingTime += $taskUserWaitingTime;
134
+                $userWaitingTimeCount++;
135
+                if ($taskUserWaitingTime >= $maxUserWaitingTime) {
136
+                    $maxUserWaitingTime = $taskUserWaitingTime;
137
+                }
138
+            }
139
+            // input/output sizes
140
+            if ($task->getStatus() === Task::STATUS_SUCCESSFUL) {
141
+                $outputString = json_encode($task->getOutput());
142
+                if ($outputString !== false) {
143
+                    $outputCount++;
144
+                    $outputLength = strlen($outputString);
145
+                    $outputSum += $outputLength;
146
+                    if ($outputLength > $maxOutputSize) {
147
+                        $maxOutputSize = $outputLength;
148
+                    }
149
+                }
150
+            }
151
+            $inputString = json_encode($task->getInput());
152
+            if ($inputString !== false) {
153
+                $inputCount++;
154
+                $inputLength = strlen($inputString);
155
+                $inputSum += $inputLength;
156
+                if ($inputLength > $maxInputSize) {
157
+                    $maxInputSize = $inputLength;
158
+                }
159
+            }
160
+        }
161 161
 
162
-		if ($runningTimeCount > 0) {
163
-			$stats['Max running time'] = $maxRunningTime;
164
-			$averageRunningTime = $totalRunningTime / $runningTimeCount;
165
-			$stats['Average running time'] = (int)$averageRunningTime;
166
-			$stats['Running time count'] = $runningTimeCount;
167
-		}
168
-		if ($queuingTimeCount > 0) {
169
-			$stats['Max queuing time'] = $maxQueuingTime;
170
-			$averageQueuingTime = $totalQueuingTime / $queuingTimeCount;
171
-			$stats['Average queuing time'] = (int)$averageQueuingTime;
172
-			$stats['Queuing time count'] = $queuingTimeCount;
173
-		}
174
-		if ($userWaitingTimeCount > 0) {
175
-			$stats['Max user waiting time'] = $maxUserWaitingTime;
176
-			$averageUserWaitingTime = $totalUserWaitingTime / $userWaitingTimeCount;
177
-			$stats['Average user waiting time'] = (int)$averageUserWaitingTime;
178
-			$stats['User waiting time count'] = $userWaitingTimeCount;
179
-		}
180
-		if ($outputCount > 0) {
181
-			$stats['Max output size (bytes)'] = $maxOutputSize;
182
-			$averageOutputSize = $outputSum / $outputCount;
183
-			$stats['Average output size (bytes)'] = (int)$averageOutputSize;
184
-			$stats['Number of tasks with output'] = $outputCount;
185
-		}
186
-		if ($inputCount > 0) {
187
-			$stats['Max input size (bytes)'] = $maxInputSize;
188
-			$averageInputSize = $inputSum / $inputCount;
189
-			$stats['Average input size (bytes)'] = (int)$averageInputSize;
190
-			$stats['Number of tasks with input'] = $inputCount;
191
-		}
162
+        if ($runningTimeCount > 0) {
163
+            $stats['Max running time'] = $maxRunningTime;
164
+            $averageRunningTime = $totalRunningTime / $runningTimeCount;
165
+            $stats['Average running time'] = (int)$averageRunningTime;
166
+            $stats['Running time count'] = $runningTimeCount;
167
+        }
168
+        if ($queuingTimeCount > 0) {
169
+            $stats['Max queuing time'] = $maxQueuingTime;
170
+            $averageQueuingTime = $totalQueuingTime / $queuingTimeCount;
171
+            $stats['Average queuing time'] = (int)$averageQueuingTime;
172
+            $stats['Queuing time count'] = $queuingTimeCount;
173
+        }
174
+        if ($userWaitingTimeCount > 0) {
175
+            $stats['Max user waiting time'] = $maxUserWaitingTime;
176
+            $averageUserWaitingTime = $totalUserWaitingTime / $userWaitingTimeCount;
177
+            $stats['Average user waiting time'] = (int)$averageUserWaitingTime;
178
+            $stats['User waiting time count'] = $userWaitingTimeCount;
179
+        }
180
+        if ($outputCount > 0) {
181
+            $stats['Max output size (bytes)'] = $maxOutputSize;
182
+            $averageOutputSize = $outputSum / $outputCount;
183
+            $stats['Average output size (bytes)'] = (int)$averageOutputSize;
184
+            $stats['Number of tasks with output'] = $outputCount;
185
+        }
186
+        if ($inputCount > 0) {
187
+            $stats['Max input size (bytes)'] = $maxInputSize;
188
+            $averageInputSize = $inputSum / $inputCount;
189
+            $stats['Average input size (bytes)'] = (int)$averageInputSize;
190
+            $stats['Number of tasks with input'] = $inputCount;
191
+        }
192 192
 
193
-		$this->writeArrayInOutputFormat($input, $output, $stats);
194
-		return 0;
195
-	}
193
+        $this->writeArrayInOutputFormat($input, $output, $stats);
194
+        return 0;
195
+    }
196 196
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
 		$type = $input->getOption('type');
82 82
 		$appId = $input->getOption('appId');
83 83
 		$customId = $input->getOption('customId');
84
-		$status = $input->getOption('status') !== null ? (int)$input->getOption('status') : null;
85
-		$scheduledAfter = $input->getOption('scheduledAfter') !== null ? (int)$input->getOption('scheduledAfter') : null;
86
-		$endedBefore = $input->getOption('endedBefore') !== null ? (int)$input->getOption('endedBefore') : null;
84
+		$status = $input->getOption('status') !== null ? (int) $input->getOption('status') : null;
85
+		$scheduledAfter = $input->getOption('scheduledAfter') !== null ? (int) $input->getOption('scheduledAfter') : null;
86
+		$endedBefore = $input->getOption('endedBefore') !== null ? (int) $input->getOption('endedBefore') : null;
87 87
 
88 88
 		$tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $appId, $customId, $status, $scheduledAfter, $endedBefore);
89 89
 
@@ -162,31 +162,31 @@  discard block
 block discarded – undo
162 162
 		if ($runningTimeCount > 0) {
163 163
 			$stats['Max running time'] = $maxRunningTime;
164 164
 			$averageRunningTime = $totalRunningTime / $runningTimeCount;
165
-			$stats['Average running time'] = (int)$averageRunningTime;
165
+			$stats['Average running time'] = (int) $averageRunningTime;
166 166
 			$stats['Running time count'] = $runningTimeCount;
167 167
 		}
168 168
 		if ($queuingTimeCount > 0) {
169 169
 			$stats['Max queuing time'] = $maxQueuingTime;
170 170
 			$averageQueuingTime = $totalQueuingTime / $queuingTimeCount;
171
-			$stats['Average queuing time'] = (int)$averageQueuingTime;
171
+			$stats['Average queuing time'] = (int) $averageQueuingTime;
172 172
 			$stats['Queuing time count'] = $queuingTimeCount;
173 173
 		}
174 174
 		if ($userWaitingTimeCount > 0) {
175 175
 			$stats['Max user waiting time'] = $maxUserWaitingTime;
176 176
 			$averageUserWaitingTime = $totalUserWaitingTime / $userWaitingTimeCount;
177
-			$stats['Average user waiting time'] = (int)$averageUserWaitingTime;
177
+			$stats['Average user waiting time'] = (int) $averageUserWaitingTime;
178 178
 			$stats['User waiting time count'] = $userWaitingTimeCount;
179 179
 		}
180 180
 		if ($outputCount > 0) {
181 181
 			$stats['Max output size (bytes)'] = $maxOutputSize;
182 182
 			$averageOutputSize = $outputSum / $outputCount;
183
-			$stats['Average output size (bytes)'] = (int)$averageOutputSize;
183
+			$stats['Average output size (bytes)'] = (int) $averageOutputSize;
184 184
 			$stats['Number of tasks with output'] = $outputCount;
185 185
 		}
186 186
 		if ($inputCount > 0) {
187 187
 			$stats['Max input size (bytes)'] = $maxInputSize;
188 188
 			$averageInputSize = $inputSum / $inputCount;
189
-			$stats['Average input size (bytes)'] = (int)$averageInputSize;
189
+			$stats['Average input size (bytes)'] = (int) $averageInputSize;
190 190
 			$stats['Number of tasks with input'] = $inputCount;
191 191
 		}
192 192
 
Please login to merge, or discard this patch.
core/Command/TaskProcessing/Cleanup.php 2 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -20,76 +20,76 @@
 block discarded – undo
20 20
 use Symfony\Component\Console\Output\OutputInterface;
21 21
 
22 22
 class Cleanup extends Base {
23
-	private IAppData $appData;
23
+    private IAppData $appData;
24 24
 
25
-	public function __construct(
26
-		protected Manager $taskProcessingManager,
27
-		private TaskMapper $taskMapper,
28
-		private LoggerInterface $logger,
29
-		IAppDataFactory $appDataFactory,
30
-	) {
31
-		parent::__construct();
32
-		$this->appData = $appDataFactory->get('core');
33
-	}
25
+    public function __construct(
26
+        protected Manager $taskProcessingManager,
27
+        private TaskMapper $taskMapper,
28
+        private LoggerInterface $logger,
29
+        IAppDataFactory $appDataFactory,
30
+    ) {
31
+        parent::__construct();
32
+        $this->appData = $appDataFactory->get('core');
33
+    }
34 34
 
35
-	protected function configure() {
36
-		$this
37
-			->setName('taskprocessing:task:cleanup')
38
-			->setDescription('cleanup old tasks')
39
-			->addArgument(
40
-				'maxAgeSeconds',
41
-				InputArgument::OPTIONAL,
42
-				// default is not defined as an argument default value because we want to show a nice "4 months" value
43
-				'delete tasks that are older than this number of seconds, defaults to ' . Manager::MAX_TASK_AGE_SECONDS . ' (4 months)',
44
-			);
45
-		parent::configure();
46
-	}
35
+    protected function configure() {
36
+        $this
37
+            ->setName('taskprocessing:task:cleanup')
38
+            ->setDescription('cleanup old tasks')
39
+            ->addArgument(
40
+                'maxAgeSeconds',
41
+                InputArgument::OPTIONAL,
42
+                // default is not defined as an argument default value because we want to show a nice "4 months" value
43
+                'delete tasks that are older than this number of seconds, defaults to ' . Manager::MAX_TASK_AGE_SECONDS . ' (4 months)',
44
+            );
45
+        parent::configure();
46
+    }
47 47
 
48
-	protected function execute(InputInterface $input, OutputInterface $output): int {
49
-		$maxAgeSeconds = (int)($input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS);
50
-		$output->writeln('<comment>Cleanup up tasks older than ' . $maxAgeSeconds . ' seconds and the related output files</comment>');
48
+    protected function execute(InputInterface $input, OutputInterface $output): int {
49
+        $maxAgeSeconds = (int)($input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS);
50
+        $output->writeln('<comment>Cleanup up tasks older than ' . $maxAgeSeconds . ' seconds and the related output files</comment>');
51 51
 
52
-		$taskIdsToCleanup = [];
53
-		try {
54
-			$fileCleanupGenerator = $this->taskProcessingManager->cleanupTaskProcessingTaskFiles($maxAgeSeconds);
55
-			foreach ($fileCleanupGenerator as $cleanedUpEntry) {
56
-				$output->writeln(
57
-					"<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $cleanedUpEntry['file_name']
58
-					. ' (fileId: ' . $cleanedUpEntry['file_id'] . ', taskId: ' . $cleanedUpEntry['task_id'] . ')</info>'
59
-				);
60
-			}
61
-			$taskIdsToCleanup = $fileCleanupGenerator->getReturn();
62
-		} catch (\Exception $e) {
63
-			$this->logger->warning('Failed to delete stale task processing tasks files', ['exception' => $e]);
64
-			$output->writeln('<warning>Failed to delete stale task processing tasks files</warning>');
65
-		}
66
-		try {
67
-			$deletedTaskCount = $this->taskMapper->deleteOlderThan($maxAgeSeconds);
68
-			foreach ($taskIdsToCleanup as $taskId) {
69
-				$output->writeln("<info>\t - " . 'Deleted task ' . $taskId . ' from the database</info>');
70
-			}
71
-			$output->writeln("<comment>\t - " . 'Deleted ' . $deletedTaskCount . ' tasks from the database</comment>');
72
-		} catch (\OCP\DB\Exception $e) {
73
-			$this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]);
74
-			$output->writeln('<warning>Failed to delete stale task processing tasks</warning>');
75
-		}
76
-		try {
77
-			$textToImageDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('text2image'), $maxAgeSeconds);
78
-			foreach ($textToImageDeletedFileNames as $entry) {
79
-				$output->writeln("<info>\t - " . 'Deleted appData/core/text2image/' . $entry . '</info>');
80
-			}
81
-		} catch (NotFoundException $e) {
82
-			// noop
83
-		}
84
-		try {
85
-			$audioToTextDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('audio2text'), $maxAgeSeconds);
86
-			foreach ($audioToTextDeletedFileNames as $entry) {
87
-				$output->writeln("<info>\t - " . 'Deleted appData/core/audio2text/' . $entry . '</info>');
88
-			}
89
-		} catch (NotFoundException $e) {
90
-			// noop
91
-		}
52
+        $taskIdsToCleanup = [];
53
+        try {
54
+            $fileCleanupGenerator = $this->taskProcessingManager->cleanupTaskProcessingTaskFiles($maxAgeSeconds);
55
+            foreach ($fileCleanupGenerator as $cleanedUpEntry) {
56
+                $output->writeln(
57
+                    "<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $cleanedUpEntry['file_name']
58
+                    . ' (fileId: ' . $cleanedUpEntry['file_id'] . ', taskId: ' . $cleanedUpEntry['task_id'] . ')</info>'
59
+                );
60
+            }
61
+            $taskIdsToCleanup = $fileCleanupGenerator->getReturn();
62
+        } catch (\Exception $e) {
63
+            $this->logger->warning('Failed to delete stale task processing tasks files', ['exception' => $e]);
64
+            $output->writeln('<warning>Failed to delete stale task processing tasks files</warning>');
65
+        }
66
+        try {
67
+            $deletedTaskCount = $this->taskMapper->deleteOlderThan($maxAgeSeconds);
68
+            foreach ($taskIdsToCleanup as $taskId) {
69
+                $output->writeln("<info>\t - " . 'Deleted task ' . $taskId . ' from the database</info>');
70
+            }
71
+            $output->writeln("<comment>\t - " . 'Deleted ' . $deletedTaskCount . ' tasks from the database</comment>');
72
+        } catch (\OCP\DB\Exception $e) {
73
+            $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]);
74
+            $output->writeln('<warning>Failed to delete stale task processing tasks</warning>');
75
+        }
76
+        try {
77
+            $textToImageDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('text2image'), $maxAgeSeconds);
78
+            foreach ($textToImageDeletedFileNames as $entry) {
79
+                $output->writeln("<info>\t - " . 'Deleted appData/core/text2image/' . $entry . '</info>');
80
+            }
81
+        } catch (NotFoundException $e) {
82
+            // noop
83
+        }
84
+        try {
85
+            $audioToTextDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('audio2text'), $maxAgeSeconds);
86
+            foreach ($audioToTextDeletedFileNames as $entry) {
87
+                $output->writeln("<info>\t - " . 'Deleted appData/core/audio2text/' . $entry . '</info>');
88
+            }
89
+        } catch (NotFoundException $e) {
90
+            // noop
91
+        }
92 92
 
93
-		return 0;
94
-	}
93
+        return 0;
94
+    }
95 95
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -40,22 +40,22 @@  discard block
 block discarded – undo
40 40
 				'maxAgeSeconds',
41 41
 				InputArgument::OPTIONAL,
42 42
 				// default is not defined as an argument default value because we want to show a nice "4 months" value
43
-				'delete tasks that are older than this number of seconds, defaults to ' . Manager::MAX_TASK_AGE_SECONDS . ' (4 months)',
43
+				'delete tasks that are older than this number of seconds, defaults to '.Manager::MAX_TASK_AGE_SECONDS.' (4 months)',
44 44
 			);
45 45
 		parent::configure();
46 46
 	}
47 47
 
48 48
 	protected function execute(InputInterface $input, OutputInterface $output): int {
49
-		$maxAgeSeconds = (int)($input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS);
50
-		$output->writeln('<comment>Cleanup up tasks older than ' . $maxAgeSeconds . ' seconds and the related output files</comment>');
49
+		$maxAgeSeconds = (int) ($input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS);
50
+		$output->writeln('<comment>Cleanup up tasks older than '.$maxAgeSeconds.' seconds and the related output files</comment>');
51 51
 
52 52
 		$taskIdsToCleanup = [];
53 53
 		try {
54 54
 			$fileCleanupGenerator = $this->taskProcessingManager->cleanupTaskProcessingTaskFiles($maxAgeSeconds);
55 55
 			foreach ($fileCleanupGenerator as $cleanedUpEntry) {
56 56
 				$output->writeln(
57
-					"<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $cleanedUpEntry['file_name']
58
-					. ' (fileId: ' . $cleanedUpEntry['file_id'] . ', taskId: ' . $cleanedUpEntry['task_id'] . ')</info>'
57
+					"<info>\t - ".'Deleted appData/core/TaskProcessing/'.$cleanedUpEntry['file_name']
58
+					. ' (fileId: '.$cleanedUpEntry['file_id'].', taskId: '.$cleanedUpEntry['task_id'].')</info>'
59 59
 				);
60 60
 			}
61 61
 			$taskIdsToCleanup = $fileCleanupGenerator->getReturn();
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 		try {
67 67
 			$deletedTaskCount = $this->taskMapper->deleteOlderThan($maxAgeSeconds);
68 68
 			foreach ($taskIdsToCleanup as $taskId) {
69
-				$output->writeln("<info>\t - " . 'Deleted task ' . $taskId . ' from the database</info>');
69
+				$output->writeln("<info>\t - ".'Deleted task '.$taskId.' from the database</info>');
70 70
 			}
71
-			$output->writeln("<comment>\t - " . 'Deleted ' . $deletedTaskCount . ' tasks from the database</comment>');
71
+			$output->writeln("<comment>\t - ".'Deleted '.$deletedTaskCount.' tasks from the database</comment>');
72 72
 		} catch (\OCP\DB\Exception $e) {
73 73
 			$this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]);
74 74
 			$output->writeln('<warning>Failed to delete stale task processing tasks</warning>');
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		try {
77 77
 			$textToImageDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('text2image'), $maxAgeSeconds);
78 78
 			foreach ($textToImageDeletedFileNames as $entry) {
79
-				$output->writeln("<info>\t - " . 'Deleted appData/core/text2image/' . $entry . '</info>');
79
+				$output->writeln("<info>\t - ".'Deleted appData/core/text2image/'.$entry.'</info>');
80 80
 			}
81 81
 		} catch (NotFoundException $e) {
82 82
 			// noop
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		try {
85 85
 			$audioToTextDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('audio2text'), $maxAgeSeconds);
86 86
 			foreach ($audioToTextDeletedFileNames as $entry) {
87
-				$output->writeln("<info>\t - " . 'Deleted appData/core/audio2text/' . $entry . '</info>');
87
+				$output->writeln("<info>\t - ".'Deleted appData/core/audio2text/'.$entry.'</info>');
88 88
 			}
89 89
 		} catch (NotFoundException $e) {
90 90
 			// noop
Please login to merge, or discard this patch.