Skip to content

Commit 8fdd877

Browse files
Merge pull request #12 from opensoft/check-task-move
Do not requeue move/delete policy executions over and over again
2 parents 8963f6b + 352a72d commit 8fdd877

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Command/PolicyExecuteCommand.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ private function queueMoves($type, $moveInterval, Storage $fromStorage, Storage
124124
foreach ($query->iterate(null, AbstractQuery::HYDRATE_SCALAR) as $row) {
125125
$storageFile = $row[0];
126126

127-
$this->executeMove($storageFile['id'], $toStorage, $output);
128-
129-
$queued++;
127+
$queued += $this->executeMove($storageFile['id'], $toStorage, $output);
130128
}
131129

132130
return $queued;
@@ -144,7 +142,6 @@ private function queueDeletes($type, $deleteInterval, $limit, OutputInterface $o
144142
/** @var EntityManager $em */
145143
$em = $this->getContainer()->get('doctrine')->getManager();
146144

147-
148145
$qb = $em->createQueryBuilder()
149146
->select('s')
150147
->from(StorageFile::class, 's')
@@ -166,9 +163,7 @@ private function queueDeletes($type, $deleteInterval, $limit, OutputInterface $o
166163
foreach ($query->iterate(null, AbstractQuery::HYDRATE_SCALAR) as $row) {
167164
$storageFile = $row[0];
168165

169-
$this->executeDelete($storageFile['id'], $output);
170-
171-
$queued++;
166+
$queued += $this->executeDelete($storageFile['id'], $output);
172167
}
173168

174169
return $queued;
@@ -177,6 +172,7 @@ private function queueDeletes($type, $deleteInterval, $limit, OutputInterface $o
177172
/**
178173
* @param int $storageFileId
179174
* @param OutputInterface $output
175+
* @return int The number of storage files deleted
180176
*/
181177
private function executeDelete($storageFileId, OutputInterface $output)
182178
{
@@ -189,7 +185,13 @@ private function executeDelete($storageFileId, OutputInterface $output)
189185
$task->arguments(sprintf('%d', $storageFileId));
190186
$taskManager->queueTask($task);
191187

192-
return;
188+
if ($taskManager->hasQueuedTask($task)) {
189+
$output->writeln(sprintf('Delete already queued for storage file %s... skipping', $storageFileId));
190+
191+
return 0;
192+
}
193+
194+
return 1;
193195
}
194196

195197
// Execute the delete command directly
@@ -201,12 +203,15 @@ private function executeDelete($storageFileId, OutputInterface $output)
201203
];
202204

203205
$command->run(new ArrayInput($arguments), $output);
206+
207+
return 1;
204208
}
205209

206210
/**
207211
* @param int $storageFileId
208212
* @param Storage $toStorage
209213
* @param OutputInterface $output
214+
* @return int The number of storage files that were moved
210215
*/
211216
private function executeMove($storageFileId, Storage $toStorage, OutputInterface $output)
212217
{
@@ -218,9 +223,15 @@ private function executeMove($storageFileId, Storage $toStorage, OutputInterface
218223
$task->command('storage:move-file');
219224
$task->arguments(sprintf('%d %d', $storageFileId, $toStorage->getId()));
220225
$task->timeout(300)->idleTimeout(300);
226+
227+
if ($taskManager->hasQueuedTask($task)) {
228+
$output->writeln(sprintf('Move already queued for storage file %s... skipping', $storageFileId));
229+
230+
return 0;
231+
}
221232
$taskManager->queueTask($task);
222233

223-
return;
234+
return 1;
224235
}
225236

226237
// Execute the move command directly
@@ -233,5 +244,7 @@ private function executeMove($storageFileId, Storage $toStorage, OutputInterface
233244
];
234245

235246
$command->run(new ArrayInput($arguments), $output);
247+
248+
return 1;
236249
}
237250
}

0 commit comments

Comments
 (0)