delayed project deletion

This commit is contained in:
shimon
2025-06-05 17:26:09 +03:00
parent 72e7f475ee
commit 2f081a119b
5 changed files with 4 additions and 91 deletions
-1
View File
@@ -67,7 +67,6 @@ RUN chmod +x /usr/local/bin/doctor && \
chmod +x /usr/local/bin/schedule-functions && \
chmod +x /usr/local/bin/schedule-executions && \
chmod +x /usr/local/bin/schedule-messages && \
chmod +x /usr/local/bin/schedule-projects && \
chmod +x /usr/local/bin/sdks && \
chmod +x /usr/local/bin/specs && \
chmod +x /usr/local/bin/ssl && \
+4 -26
View File
@@ -1172,32 +1172,10 @@ App::delete('/v1/projects/:projectId')
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$interval = (int)System::getEnv('_APP_PROJECTS_DELETE_EXPIRATION','3600');
$expiration = new \DateTime();
$expiration->add(new \DateInterval('PT' . $interval . 'S'));
$cronPattern = sprintf('%d %d %d %d *',
(int)$expiration->format('i'), // minute
(int)$expiration->format('G'), // hour
(int)$expiration->format('j'), // day of month
(int)$expiration->format('n') // month
);
$cronExpression = new CronExpression($cronPattern);
$scheduledAt = $cronExpression->getExpression();
$schedule = $dbForPlatform->createDocument('schedules', new Document([
'region' => $project->getAttribute('region'),
'resourceType' => 'project',
'resourceId' => $project->getId(),
'resourceInternalId' => $project->getInternalId(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
'schedule' => $scheduledAt,
'active' => true,
]));
$dbForPlatform->updateDocument('projects', $project->getId(), $project
->setAttribute('scheduleId', $schedule->getId()))
$expiration = System::getEnv('_APP_PROJECTS_DELETE_EXPIRATION','3600');
$deletedAt = DateTime::formatTz(DateTime::addSeconds(new \DateTime(), (int)$expiration));
$dbForPlatform->updateDocument('projects', $project->getId(),
$project->setAttribute('_deletedAt', $deletedAt))
;
$response->noContent();
-3
View File
@@ -1,3 +0,0 @@
#!/bin/sh
exec php /usr/src/code/app/cli.php schedule-projects $@
-2
View File
@@ -10,7 +10,6 @@ use Appwrite\Platform\Tasks\QueueRetry;
use Appwrite\Platform\Tasks\ScheduleExecutions;
use Appwrite\Platform\Tasks\ScheduleFunctions;
use Appwrite\Platform\Tasks\ScheduleMessages;
use Appwrite\Platform\Tasks\ScheduleProjects;
use Appwrite\Platform\Tasks\Screenshot;
use Appwrite\Platform\Tasks\SDKs;
use Appwrite\Platform\Tasks\Specs;
@@ -38,7 +37,6 @@ class Tasks extends Service
->addAction(ScheduleFunctions::getName(), new ScheduleFunctions())
->addAction(ScheduleExecutions::getName(), new ScheduleExecutions())
->addAction(ScheduleMessages::getName(), new ScheduleMessages())
->addAction(ScheduleProjects::getName(), new ScheduleProjects())
->addAction(Specs::getName(), new Specs())
->addAction(Upgrade::getName(), new Upgrade())
->addAction(Vars::getName(), new Vars())
@@ -1,59 +0,0 @@
<?php
namespace Appwrite\Platform\Tasks;
use Appwrite\Event\Delete;
use Utopia\Database\Database;
use Utopia\Pools\Group;
class ScheduleProjects extends ScheduleBase
{
public const UPDATE_TIMER = 3; // seconds
public const ENQUEUE_TIMER = 4; // seconds
public static function getName(): string
{
return 'schedule-projects';
}
public static function getSupportedResource(): string
{
return 'project';
}
public static function getCollectionId(): string
{
return 'projects';
}
protected function enqueueResources(Group $pools, Database $dbForPlatform, callable $getProjectDB): void
{
foreach ($this->schedules as $schedule) {
if (!$schedule['active']) {
continue;
}
$now = new \DateTime();
$scheduledAt = new \DateTime($schedule['schedule']);
if ($scheduledAt > $now) {
continue;
}
\go(function () use ($schedule, $scheduledAt, $dbForPlatform) {
(new Delete($this->publisher))
->setProject($schedule['project'])
->setType(DELETE_TYPE_DOCUMENT)
->setDocument($schedule['project'])
->trigger();
$dbForPlatform->deleteDocument('projects', $schedule['project']->getId());
$dbForPlatform->deleteDocument('schedules', $schedule['$id']);
$this->recordEnqueueDelay($scheduledAt);
unset($this->schedules[$schedule['$internalId']]);
});
}
}
}