1
0
Fork 0
mirror of synced 2024-06-29 19:50:26 +12:00

refactor(workers): remove db exceptions from deletes

This commit is contained in:
Torsten Dittmann 2021-11-23 17:11:52 +01:00
parent 38499e0a5d
commit 7e3df6fc96

View file

@ -120,7 +120,8 @@ class DeletesV1 extends Worker
*/ */
protected function deleteUsageStats(int $timestamp1d, int $timestamp30m) protected function deleteUsageStats(int $timestamp1d, int $timestamp30m)
{ {
$this->deleteForProjectIds(function (string $projectId, Database $dbForInternal, Database $dbForExternal) use ($timestamp1d, $timestamp30m) { $this->deleteForProjectIds(function (string $projectId) use ($timestamp1d, $timestamp30m) {
$dbForInternal = $this->getInternalDB($projectId);
// Delete Usage stats // Delete Usage stats
$this->deleteByGroup('stats', [ $this->deleteByGroup('stats', [
new Query('time', Query::TYPE_LESSER, [$timestamp1d]), new Query('time', Query::TYPE_LESSER, [$timestamp1d]),
@ -198,7 +199,8 @@ class DeletesV1 extends Worker
*/ */
protected function deleteExecutionLogs(int $timestamp): void protected function deleteExecutionLogs(int $timestamp): void
{ {
$this->deleteForProjectIds(function (string $projectId, Database $dbForInternal, Database $dbForExternal) use ($timestamp) { $this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
$dbForInternal = $this->getInternalDB($projectId);
// Delete Executions // Delete Executions
$this->deleteByGroup('executions', [ $this->deleteByGroup('executions', [
new Query('dateCreated', Query::TYPE_LESSER, [$timestamp]) new Query('dateCreated', Query::TYPE_LESSER, [$timestamp])
@ -211,7 +213,8 @@ class DeletesV1 extends Worker
*/ */
protected function deleteRealtimeUsage(int $timestamp): void protected function deleteRealtimeUsage(int $timestamp): void
{ {
$this->deleteForProjectIds(function (string $projectId, Database $dbForInternal, Database $dbForExternal) use ($timestamp) { $this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
$dbForInternal = $this->getInternalDB($projectId);
// Delete Dead Realtime Logs // Delete Dead Realtime Logs
$this->deleteByGroup('realtime', [ $this->deleteByGroup('realtime', [
new Query('timestamp', Query::TYPE_LESSER, [$timestamp]) new Query('timestamp', Query::TYPE_LESSER, [$timestamp])
@ -228,7 +231,8 @@ class DeletesV1 extends Worker
throw new Exception('Failed to delete audit logs. No timestamp provided'); throw new Exception('Failed to delete audit logs. No timestamp provided');
} }
$this->deleteForProjectIds(function (string $projectId, Database $dbForInternal, Database $dbForExternal) use ($timestamp) { $this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
$dbForInternal = $this->getInternalDB($projectId);
$timeLimit = new TimeLimit("", 0, 1, $dbForInternal); $timeLimit = new TimeLimit("", 0, 1, $dbForInternal);
$abuse = new Abuse($timeLimit); $abuse = new Abuse($timeLimit);
@ -247,7 +251,8 @@ class DeletesV1 extends Worker
if ($timestamp == 0) { if ($timestamp == 0) {
throw new Exception('Failed to delete audit logs. No timestamp provided'); throw new Exception('Failed to delete audit logs. No timestamp provided');
} }
$this->deleteForProjectIds(function (string $projectId, Database $dbForInternal, Database $dbForExternal) use ($timestamp) { $this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
$dbForInternal = $this->getInternalDB($projectId);
$audit = new Audit($dbForInternal); $audit = new Audit($dbForInternal);
$status = $audit->cleanup($timestamp); $status = $audit->cleanup($timestamp);
if (!$status) { if (!$status) {
@ -338,14 +343,7 @@ class DeletesV1 extends Worker
Console::info('Executing delete function for chunk #' . $chunk . '. Found ' . $sum . ' projects'); Console::info('Executing delete function for chunk #' . $chunk . '. Found ' . $sum . ' projects');
foreach ($projectIds as $projectId) { foreach ($projectIds as $projectId) {
if (!($dbForInternal = $this->getInternalDB($projectId))) { $callback($projectId);
throw new Exception('Failed to get projectDB for project ' . $projectId);
}
if (!($dbForExternal = $this->getExternalDB($projectId))) {
throw new Exception('Failed to get projectDB for project ' . $projectId);
}
$callback($projectId, $dbForInternal, $dbForExternal);
$count++; $count++;
} }
} }