mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge branch '1.6.x' into docs-clarify-updates-endpoints-2
This commit is contained in:
commit
bbb6b2d256
29 changed files with 238 additions and 311 deletions
|
|
@ -268,6 +268,24 @@ return [
|
||||||
'question' => '',
|
'question' => '',
|
||||||
'filter' => ''
|
'filter' => ''
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => '_APP_COMPRESSION_ENABLED',
|
||||||
|
'description' => 'This option allows you to enable or disable the response compression for the Appwrite API. It\'s enabled by default with value "enabled", and to disable it, pass value "disabled".',
|
||||||
|
'introduction' => '1.6.0',
|
||||||
|
'default' => 'enabled',
|
||||||
|
'required' => false,
|
||||||
|
'question' => '',
|
||||||
|
'filter' => ''
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => '_APP_COMPRESSION_MIN_SIZE_BYTES',
|
||||||
|
'description' => 'This option allows you to set the minimum size in bytes for the response compression to be applied. The default value is 1024 bytes.',
|
||||||
|
'introduction' => '1.6.0',
|
||||||
|
'default' => 1024,
|
||||||
|
'required' => false,
|
||||||
|
'question' => '',
|
||||||
|
'filter' => ''
|
||||||
|
]
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,7 @@ App::post('/v1/functions')
|
||||||
$allEvents = Event::generateEvents('rules.[ruleId].create', [
|
$allEvents = Event::generateEvents('rules.[ruleId].create', [
|
||||||
'ruleId' => $rule->getId(),
|
'ruleId' => $rule->getId(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$target = Realtime::fromPayload(
|
$target = Realtime::fromPayload(
|
||||||
// Pass first, most verbose event pattern
|
// Pass first, most verbose event pattern
|
||||||
event: $allEvents[0],
|
event: $allEvents[0],
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ $parseLabel = function (string $label, array $responsePayload, array $requestPar
|
||||||
return $label;
|
return $label;
|
||||||
};
|
};
|
||||||
|
|
||||||
$eventDatabaseListener = function (Document $document, Response $response, Event $queueForEvents, Func $queueForFunctions, Webhook $queueForWebhooks, Realtime $queueForRealtime) {
|
$eventDatabaseListener = function (Document $project, Document $document, Response $response, Event $queueForEvents, Func $queueForFunctions, Webhook $queueForWebhooks, Realtime $queueForRealtime) {
|
||||||
// Only trigger events for user creation with the database listener.
|
// Only trigger events for user creation with the database listener.
|
||||||
if ($document->getCollection() !== 'users') {
|
if ($document->getCollection() !== 'users') {
|
||||||
return;
|
return;
|
||||||
|
|
@ -74,17 +74,20 @@ $eventDatabaseListener = function (Document $document, Response $response, Event
|
||||||
->from($queueForEvents)
|
->from($queueForEvents)
|
||||||
->trigger();
|
->trigger();
|
||||||
|
|
||||||
$queueForWebhooks
|
|
||||||
->from($queueForEvents)
|
|
||||||
->trigger();
|
|
||||||
|
|
||||||
if ($queueForEvents->getProject()->getId() === 'console') {
|
/** Trigger webhooks events only if a project has them enabled */
|
||||||
return;
|
if (!empty($project->getAttribute('webhooks'))) {
|
||||||
|
$queueForWebhooks
|
||||||
|
->from($queueForEvents)
|
||||||
|
->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
$queueForRealtime
|
/** Trigger realtime events only for non console events */
|
||||||
->from($queueForEvents)
|
if ($queueForEvents->getProject()->getId() !== 'console') {
|
||||||
->trigger();
|
$queueForRealtime
|
||||||
|
->from($queueForEvents)
|
||||||
|
->trigger();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$usageDatabaseListener = function (string $event, Document $document, Usage $queueForUsage) {
|
$usageDatabaseListener = function (string $event, Document $document, Usage $queueForUsage) {
|
||||||
|
|
@ -527,6 +530,7 @@ App::init()
|
||||||
->on(Database::EVENT_DOCUMENT_CREATE, 'calculate-usage', fn ($event, $document) => $usageDatabaseListener($event, $document, $queueForUsage))
|
->on(Database::EVENT_DOCUMENT_CREATE, 'calculate-usage', fn ($event, $document) => $usageDatabaseListener($event, $document, $queueForUsage))
|
||||||
->on(Database::EVENT_DOCUMENT_DELETE, 'calculate-usage', fn ($event, $document) => $usageDatabaseListener($event, $document, $queueForUsage))
|
->on(Database::EVENT_DOCUMENT_DELETE, 'calculate-usage', fn ($event, $document) => $usageDatabaseListener($event, $document, $queueForUsage))
|
||||||
->on(Database::EVENT_DOCUMENT_CREATE, 'create-trigger-events', fn ($event, $document) => $eventDatabaseListener(
|
->on(Database::EVENT_DOCUMENT_CREATE, 'create-trigger-events', fn ($event, $document) => $eventDatabaseListener(
|
||||||
|
$project,
|
||||||
$document,
|
$document,
|
||||||
$response,
|
$response,
|
||||||
$queueForEventsClone->from($queueForEvents),
|
$queueForEventsClone->from($queueForEvents),
|
||||||
|
|
@ -679,10 +683,6 @@ App::shutdown()
|
||||||
$queueForEvents->setPayload($responsePayload);
|
$queueForEvents->setPayload($responsePayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
$queueForWebhooks
|
|
||||||
->from($queueForEvents)
|
|
||||||
->trigger();
|
|
||||||
|
|
||||||
$queueForFunctions
|
$queueForFunctions
|
||||||
->from($queueForEvents)
|
->from($queueForEvents)
|
||||||
->trigger();
|
->trigger();
|
||||||
|
|
@ -692,6 +692,17 @@ App::shutdown()
|
||||||
->from($queueForEvents)
|
->from($queueForEvents)
|
||||||
->trigger();
|
->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Trigger webhooks events only if a project has them enabled
|
||||||
|
* A future optimisation is to only trigger webhooks if the webhook is "enabled"
|
||||||
|
* But it might have performance implications on the API due to the number of webhooks etc.
|
||||||
|
* Some profiling is needed to see if this is a problem.
|
||||||
|
*/
|
||||||
|
if (!empty($project->getAttribute('webhooks'))) {
|
||||||
|
$queueForWebhooks
|
||||||
|
->from($queueForEvents)
|
||||||
|
->trigger();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$route = $utopia->getRoute();
|
$route = $utopia->getRoute();
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ $http->on(Constant::EVENT_REQUEST, function (SwooleRequest $swooleRequest, Swool
|
||||||
}
|
}
|
||||||
|
|
||||||
$app = new App('UTC');
|
$app = new App('UTC');
|
||||||
$app->setCompression(true);
|
$app->setCompression(System::getEnv('_APP_COMPRESSION_ENABLED', 'enabled') === 'enabled');
|
||||||
$app->setCompressionMinSize(intval(System::getEnv('_APP_COMPRESSION_MIN_SIZE_BYTES', '1024'))); // 1KB
|
$app->setCompressionMinSize(intval(System::getEnv('_APP_COMPRESSION_MIN_SIZE_BYTES', '1024'))); // 1KB
|
||||||
|
|
||||||
$pools = $register->get('pools');
|
$pools = $register->get('pools');
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,7 @@ const DELETE_TYPE_TOPIC = 'topic';
|
||||||
const DELETE_TYPE_TARGET = 'target';
|
const DELETE_TYPE_TARGET = 'target';
|
||||||
const DELETE_TYPE_EXPIRED_TARGETS = 'invalid_targets';
|
const DELETE_TYPE_EXPIRED_TARGETS = 'invalid_targets';
|
||||||
const DELETE_TYPE_SESSION_TARGETS = 'session_targets';
|
const DELETE_TYPE_SESSION_TARGETS = 'session_targets';
|
||||||
|
const DELETE_TYPE_MAINTENANCE = 'maintenance';
|
||||||
|
|
||||||
// Message types
|
// Message types
|
||||||
const MESSAGE_SEND_TYPE_INTERNAL = 'internal';
|
const MESSAGE_SEND_TYPE_INTERNAL = 'internal';
|
||||||
|
|
|
||||||
34
composer.lock
generated
34
composer.lock
generated
|
|
@ -1430,16 +1430,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "open-telemetry/gen-otlp-protobuf",
|
"name": "open-telemetry/gen-otlp-protobuf",
|
||||||
"version": "1.2.1",
|
"version": "1.5.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/opentelemetry-php/gen-otlp-protobuf.git",
|
"url": "https://github.com/opentelemetry-php/gen-otlp-protobuf.git",
|
||||||
"reference": "66c3b98e998a726691c92e6405a82e6e7b8b169d"
|
"reference": "585bafddd4ae6565de154610b10a787a455c9ba0"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/opentelemetry-php/gen-otlp-protobuf/zipball/66c3b98e998a726691c92e6405a82e6e7b8b169d",
|
"url": "https://api.github.com/repos/opentelemetry-php/gen-otlp-protobuf/zipball/585bafddd4ae6565de154610b10a787a455c9ba0",
|
||||||
"reference": "66c3b98e998a726691c92e6405a82e6e7b8b169d",
|
"reference": "585bafddd4ae6565de154610b10a787a455c9ba0",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
@ -1489,7 +1489,7 @@
|
||||||
"issues": "https://github.com/open-telemetry/opentelemetry-php/issues",
|
"issues": "https://github.com/open-telemetry/opentelemetry-php/issues",
|
||||||
"source": "https://github.com/open-telemetry/opentelemetry-php"
|
"source": "https://github.com/open-telemetry/opentelemetry-php"
|
||||||
},
|
},
|
||||||
"time": "2024-10-30T11:49:49+00:00"
|
"time": "2025-01-15T23:07:07+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "open-telemetry/sdk",
|
"name": "open-telemetry/sdk",
|
||||||
|
|
@ -3379,16 +3379,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/compression",
|
"name": "utopia-php/compression",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/utopia-php/compression.git",
|
"url": "https://github.com/utopia-php/compression.git",
|
||||||
"reference": "6062f70596415f8d5de40a589367b0eb2a435f98"
|
"reference": "66f093557ba66d98245e562036182016c7dcfe8a"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/utopia-php/compression/zipball/6062f70596415f8d5de40a589367b0eb2a435f98",
|
"url": "https://api.github.com/repos/utopia-php/compression/zipball/66f093557ba66d98245e562036182016c7dcfe8a",
|
||||||
"reference": "6062f70596415f8d5de40a589367b0eb2a435f98",
|
"reference": "66f093557ba66d98245e562036182016c7dcfe8a",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
@ -3419,9 +3419,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/utopia-php/compression/issues",
|
"issues": "https://github.com/utopia-php/compression/issues",
|
||||||
"source": "https://github.com/utopia-php/compression/tree/0.1.2"
|
"source": "https://github.com/utopia-php/compression/tree/0.1.3"
|
||||||
},
|
},
|
||||||
"time": "2024-11-08T14:59:54+00:00"
|
"time": "2025-01-15T15:15:51+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/config",
|
"name": "utopia-php/config",
|
||||||
|
|
@ -3678,16 +3678,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/framework",
|
"name": "utopia-php/framework",
|
||||||
"version": "0.33.15",
|
"version": "0.33.16",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/utopia-php/http.git",
|
"url": "https://github.com/utopia-php/http.git",
|
||||||
"reference": "83b0628900c2c53e8c3efbf069f3e13050295edc"
|
"reference": "e91d4c560d1b809e25faa63d564fef034363b50f"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/utopia-php/http/zipball/83b0628900c2c53e8c3efbf069f3e13050295edc",
|
"url": "https://api.github.com/repos/utopia-php/http/zipball/e91d4c560d1b809e25faa63d564fef034363b50f",
|
||||||
"reference": "83b0628900c2c53e8c3efbf069f3e13050295edc",
|
"reference": "e91d4c560d1b809e25faa63d564fef034363b50f",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
@ -3719,9 +3719,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/utopia-php/http/issues",
|
"issues": "https://github.com/utopia-php/http/issues",
|
||||||
"source": "https://github.com/utopia-php/http/tree/0.33.15"
|
"source": "https://github.com/utopia-php/http/tree/0.33.16"
|
||||||
},
|
},
|
||||||
"time": "2024-12-10T13:07:04+00:00"
|
"time": "2025-01-16T15:58:50+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/image",
|
"name": "utopia-php/image",
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Audit extends Event
|
class Audit extends Event
|
||||||
|
|
@ -139,20 +138,13 @@ class Audit extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the event and sends it to the audit worker.
|
* Prepare payload for queue.
|
||||||
*
|
*
|
||||||
* @return string|bool
|
* @return array
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'user' => $this->user,
|
'user' => $this->user,
|
||||||
'payload' => $this->payload,
|
'payload' => $this->payload,
|
||||||
|
|
@ -162,6 +154,6 @@ class Audit extends Event
|
||||||
'userAgent' => $this->userAgent,
|
'userAgent' => $this->userAgent,
|
||||||
'event' => $this->event,
|
'event' => $this->event,
|
||||||
'hostname' => $this->hostname
|
'hostname' => $this->hostname
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Build extends Event
|
class Build extends Event
|
||||||
|
|
@ -105,26 +104,19 @@ class Build extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the function event and sends it to the functions worker.
|
* Prepare payload for queue.
|
||||||
*
|
*
|
||||||
* @return string|bool
|
* @return array
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'resource' => $this->resource,
|
'resource' => $this->resource,
|
||||||
'deployment' => $this->deployment,
|
'deployment' => $this->deployment,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'template' => $this->template
|
'template' => $this->template
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Certificate extends Event
|
class Certificate extends Event
|
||||||
|
|
@ -67,23 +66,16 @@ class Certificate extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the event and sends it to the certificates worker.
|
* Prepare the payload for the event
|
||||||
*
|
*
|
||||||
* @return string|bool
|
* @return array
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'domain' => $this->domain,
|
'domain' => $this->domain,
|
||||||
'skipRenewCheck' => $this->skipRenewCheck
|
'skipRenewCheck' => $this->skipRenewCheck
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\DSN\DSN;
|
use Utopia\DSN\DSN;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Database extends Event
|
class Database extends Event
|
||||||
|
|
@ -100,18 +99,8 @@ class Database extends Event
|
||||||
return $this->document;
|
return $this->document;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getQueue(): string
|
||||||
* Executes the event and send it to the database worker.
|
|
||||||
*
|
|
||||||
* @return string|bool
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function trigger(): string|bool
|
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dsn = new DSN($this->getProject()->getAttribute('database'));
|
$dsn = new DSN($this->getProject()->getAttribute('database'));
|
||||||
} catch (\InvalidArgumentException) {
|
} catch (\InvalidArgumentException) {
|
||||||
|
|
@ -119,23 +108,25 @@ class Database extends Event
|
||||||
$dsn = new DSN('mysql://' . $this->getProject()->getAttribute('database'));
|
$dsn = new DSN('mysql://' . $this->getProject()->getAttribute('database'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setQueue($dsn->getHost());
|
$this->queue = $dsn->getHost();
|
||||||
|
return $this->queue;
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
/**
|
||||||
|
* Prepare the payload for the event
|
||||||
try {
|
*
|
||||||
$result = $client->enqueue([
|
* @return array
|
||||||
'project' => $this->project,
|
*/
|
||||||
'user' => $this->user,
|
protected function preparePayload(): array
|
||||||
'type' => $this->type,
|
{
|
||||||
'collection' => $this->collection,
|
return [
|
||||||
'document' => $this->document,
|
'project' => $this->project,
|
||||||
'database' => $this->database,
|
'user' => $this->user,
|
||||||
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
'type' => $this->type,
|
||||||
]);
|
'collection' => $this->collection,
|
||||||
return $result;
|
'document' => $this->document,
|
||||||
} catch (\Throwable $th) {
|
'database' => $this->database,
|
||||||
return false;
|
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
||||||
}
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Delete extends Event
|
class Delete extends Event
|
||||||
|
|
@ -131,22 +130,14 @@ class Delete extends Event
|
||||||
return $this->document;
|
return $this->document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes this event and sends it to the deletes worker.
|
* Prepare the payload for the event
|
||||||
*
|
*
|
||||||
* @return string|bool
|
* @return array
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'document' => $this->document,
|
'document' => $this->document,
|
||||||
|
|
@ -154,6 +145,6 @@ class Delete extends Event
|
||||||
'resourceType' => $this->resourceType,
|
'resourceType' => $this->resourceType,
|
||||||
'datetime' => $this->datetime,
|
'datetime' => $this->datetime,
|
||||||
'hourlyUsageRetentionDatetime' => $this->hourlyUsageRetentionDatetime
|
'hourlyUsageRetentionDatetime' => $this->hourlyUsageRetentionDatetime
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,6 @@ class Event
|
||||||
public function setProject(Document $project): self
|
public function setProject(Document $project): self
|
||||||
{
|
{
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -312,6 +311,27 @@ class Event
|
||||||
return $this->params;
|
return $this->params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get trimmed values for sensitive/large payload fields.
|
||||||
|
* Override this method in child classes to add more fields to trim.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function trimPayload(): array
|
||||||
|
{
|
||||||
|
$trimmed = [];
|
||||||
|
|
||||||
|
if ($this->project) {
|
||||||
|
$trimmed['project'] = new Document([
|
||||||
|
'$id' => $this->project->getId(),
|
||||||
|
'$internalId' => $this->project->getInternalId(),
|
||||||
|
'database' => $this->project->getAttribute('database')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute Event.
|
* Execute Event.
|
||||||
*
|
*
|
||||||
|
|
@ -324,16 +344,30 @@ class Event
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
/** The getter is required since events like Databases need to override the queue name depending on the project */
|
||||||
|
$client = new Client($this->getQueue(), $this->connection);
|
||||||
|
|
||||||
return $client->enqueue([
|
// Merge the base payload with any trimmed values
|
||||||
|
$payload = array_merge($this->preparePayload(), $this->trimPayload());
|
||||||
|
|
||||||
|
return $client->enqueue($payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare payload for queue. Can be overridden by child classes to customize payload.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function preparePayload(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'user' => $this->user,
|
'user' => $this->user,
|
||||||
'userId' => $this->userId,
|
'userId' => $this->userId,
|
||||||
'payload' => $this->payload,
|
'payload' => $this->payload,
|
||||||
'context' => $this->context,
|
'context' => $this->context,
|
||||||
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Func extends Event
|
class Func extends Event
|
||||||
|
|
@ -173,13 +172,13 @@ class Func extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns set custom data for the function event.
|
* Returns set JWT for the function event.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getData(): string
|
public function getJWT(): string
|
||||||
{
|
{
|
||||||
return $this->data;
|
return $this->jwt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -191,37 +190,19 @@ class Func extends Event
|
||||||
public function setJWT(string $jwt): self
|
public function setJWT(string $jwt): self
|
||||||
{
|
{
|
||||||
$this->jwt = $jwt;
|
$this->jwt = $jwt;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns set JWT for the function event.
|
* Prepare payload for the function event.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getJWT(): string
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
return $this->jwt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the function event and sends it to the functions worker.
|
|
||||||
*
|
|
||||||
* @return string|bool
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function trigger(): string|bool
|
|
||||||
{
|
|
||||||
if ($this->paused) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
$events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null;
|
$events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null;
|
||||||
|
|
||||||
return $client->enqueue([
|
return [
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'user' => $this->user,
|
'user' => $this->user,
|
||||||
'userId' => $this->userId,
|
'userId' => $this->userId,
|
||||||
|
|
@ -236,6 +217,6 @@ class Func extends Event
|
||||||
'path' => $this->path,
|
'path' => $this->path,
|
||||||
'headers' => $this->headers,
|
'headers' => $this->headers,
|
||||||
'method' => $this->method,
|
'method' => $this->method,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Mail extends Event
|
class Mail extends Event
|
||||||
|
|
@ -397,20 +396,13 @@ class Mail extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the event and sends it to the mails worker.
|
* Prepare the payload for the event
|
||||||
*
|
*
|
||||||
* @return string|bool
|
* @return array
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'recipient' => $this->recipient,
|
'recipient' => $this->recipient,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
|
|
@ -421,6 +413,6 @@ class Mail extends Event
|
||||||
'variables' => $this->variables,
|
'variables' => $this->variables,
|
||||||
'attachment' => $this->attachment,
|
'attachment' => $this->attachment,
|
||||||
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Messaging extends Event
|
class Messaging extends Event
|
||||||
|
|
@ -176,19 +175,13 @@ class Messaging extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the event and sends it to the messaging worker.
|
* Prepare the payload for the event
|
||||||
* @return string|bool
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function trigger(): string | bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'user' => $this->user,
|
'user' => $this->user,
|
||||||
|
|
@ -196,6 +189,6 @@ class Messaging extends Event
|
||||||
'message' => $this->message,
|
'message' => $this->message,
|
||||||
'recipients' => $this->recipients,
|
'recipients' => $this->recipients,
|
||||||
'providerType' => $this->providerType,
|
'providerType' => $this->providerType,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Migration extends Event
|
class Migration extends Event
|
||||||
|
|
@ -68,23 +67,16 @@ class Migration extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the migration event and sends it to the migrations worker.
|
* Prepare the payload for the migration event.
|
||||||
*
|
*
|
||||||
* @return string|bool
|
* @return array
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'project' => $this->project,
|
'project' => $this->project,
|
||||||
'user' => $this->user,
|
'user' => $this->user,
|
||||||
'migration' => $this->migration,
|
'migration' => $this->migration,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Usage extends Event
|
class Usage extends Event
|
||||||
|
|
@ -51,6 +50,20 @@ class Usage extends Event
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the payload for the usage event.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function preparePayload(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'project' => $this->project,
|
||||||
|
'reduce' => $this->reduce,
|
||||||
|
'metrics' => $this->metrics,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends metrics to the usage worker.
|
* Sends metrics to the usage worker.
|
||||||
*
|
*
|
||||||
|
|
@ -58,20 +71,8 @@ class Usage extends Event
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
public function trigger(): string|bool
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
parent::trigger();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
$result = $client->enqueue([
|
|
||||||
'project' => $this->getProject(),
|
|
||||||
'reduce' => $this->reduce,
|
|
||||||
'metrics' => $this->metrics,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->metrics = [];
|
$this->metrics = [];
|
||||||
|
return true;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Queue\Client;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class UsageDump extends Event
|
class UsageDump extends Event
|
||||||
|
|
@ -32,20 +31,14 @@ class UsageDump extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends metrics to the usage worker.
|
* Prepare the payload for the usage dump event.
|
||||||
*
|
*
|
||||||
* @return string|bool
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function trigger(): string|bool
|
protected function preparePayload(): array
|
||||||
{
|
{
|
||||||
if ($this->paused) {
|
return [
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client($this->queue, $this->connection);
|
|
||||||
|
|
||||||
return $client->enqueue([
|
|
||||||
'stats' => $this->stats,
|
'stats' => $this->stats,
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Appwrite\Event;
|
namespace Appwrite\Event;
|
||||||
|
|
||||||
use Utopia\Database\Document;
|
|
||||||
use Utopia\Queue\Connection;
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class Webhook extends Event
|
class Webhook extends Event
|
||||||
|
|
@ -16,15 +15,17 @@ class Webhook extends Event
|
||||||
->setClass(Event::WEBHOOK_CLASS_NAME);
|
->setClass(Event::WEBHOOK_CLASS_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function trigger(): string|bool
|
/**
|
||||||
|
* Trim the payload for the webhook event.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function trimPayload(): array
|
||||||
{
|
{
|
||||||
/** Filter out context and trim project to keep the payload small */
|
$trimmed = parent::trimPayload();
|
||||||
$this->context = [];
|
if (isset($this->context)) {
|
||||||
$this->project = new Document([
|
$trimmed['context'] = [];
|
||||||
'$id' => $this->project->getId(),
|
}
|
||||||
'$internalId' => $this->project->getInternalId(),
|
return $trimmed;
|
||||||
]);
|
|
||||||
|
|
||||||
return parent::trigger();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,12 @@ class Maintenance extends Action
|
||||||
Console::info("[{$time}] Notifying workers with maintenance tasks every {$interval} seconds");
|
Console::info("[{$time}] Notifying workers with maintenance tasks every {$interval} seconds");
|
||||||
|
|
||||||
$this->foreachProject($dbForPlatform, function (Document $project) use ($queueForDeletes, $usageStatsRetentionHourly) {
|
$this->foreachProject($dbForPlatform, function (Document $project) use ($queueForDeletes, $usageStatsRetentionHourly) {
|
||||||
$queueForDeletes->setProject($project);
|
$queueForDeletes
|
||||||
|
->setType(DELETE_TYPE_MAINTENANCE)
|
||||||
|
->setProject($project)
|
||||||
|
->setUsageRetentionHourlyDateTime(DateTime::addSeconds(new \DateTime(), -1 * $usageStatsRetentionHourly))
|
||||||
|
->trigger();
|
||||||
|
|
||||||
$this->notifyProjects($queueForDeletes, $usageStatsRetentionHourly);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->notifyDeleteConnections($queueForDeletes);
|
$this->notifyDeleteConnections($queueForDeletes);
|
||||||
|
|
@ -59,18 +62,6 @@ class Maintenance extends Action
|
||||||
}, $interval, $delay);
|
}, $interval, $delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook to allow sub-classes to extend project-level maintenance functionality.
|
|
||||||
*/
|
|
||||||
protected function notifyProjects(Delete $queueForDeletes, int $usageStatsRetentionHourly): void
|
|
||||||
{
|
|
||||||
$this->notifyDeleteTargets($queueForDeletes);
|
|
||||||
$this->notifyDeleteExecutionLogs($queueForDeletes);
|
|
||||||
$this->notifyDeleteAuditLogs($queueForDeletes);
|
|
||||||
$this->notifyDeleteUsageStats($usageStatsRetentionHourly, $queueForDeletes);
|
|
||||||
$this->notifyDeleteExpiredSessions($queueForDeletes);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function foreachProject(Database $dbForPlatform, callable $callback): void
|
protected function foreachProject(Database $dbForPlatform, callable $callback): void
|
||||||
{
|
{
|
||||||
// TODO: @Meldiron name of this method no longer matches. It does not delete, and it gives whole document
|
// TODO: @Meldiron name of this method no longer matches. It does not delete, and it gives whole document
|
||||||
|
|
@ -98,28 +89,6 @@ class Maintenance extends Action
|
||||||
Console::info("Found {$count} projects " . ($executionEnd - $executionStart) . " seconds");
|
Console::info("Found {$count} projects " . ($executionEnd - $executionStart) . " seconds");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function notifyDeleteExecutionLogs(Delete $queueForDeletes): void
|
|
||||||
{
|
|
||||||
$queueForDeletes
|
|
||||||
->setType(DELETE_TYPE_EXECUTIONS)
|
|
||||||
->trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function notifyDeleteAuditLogs(Delete $queueForDeletes): void
|
|
||||||
{
|
|
||||||
$queueForDeletes
|
|
||||||
->setType(DELETE_TYPE_AUDIT)
|
|
||||||
->trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function notifyDeleteUsageStats(int $usageStatsRetentionHourly, Delete $queueForDeletes): void
|
|
||||||
{
|
|
||||||
$queueForDeletes
|
|
||||||
->setType(DELETE_TYPE_USAGE)
|
|
||||||
->setUsageRetentionHourlyDateTime(DateTime::addSeconds(new \DateTime(), -1 * $usageStatsRetentionHourly))
|
|
||||||
->trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function notifyDeleteConnections(Delete $queueForDeletes): void
|
private function notifyDeleteConnections(Delete $queueForDeletes): void
|
||||||
{
|
{
|
||||||
$queueForDeletes
|
$queueForDeletes
|
||||||
|
|
@ -128,13 +97,6 @@ class Maintenance extends Action
|
||||||
->trigger();
|
->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function notifyDeleteExpiredSessions(Delete $queueForDeletes): void
|
|
||||||
{
|
|
||||||
$queueForDeletes
|
|
||||||
->setType(DELETE_TYPE_SESSIONS)
|
|
||||||
->trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function renewCertificates(Database $dbForPlatform, Certificate $queueForCertificate): void
|
private function renewCertificates(Database $dbForPlatform, Certificate $queueForCertificate): void
|
||||||
{
|
{
|
||||||
$time = DateTime::now();
|
$time = DateTime::now();
|
||||||
|
|
@ -177,11 +139,4 @@ class Maintenance extends Action
|
||||||
->setDatetime(DateTime::addSeconds(new \DateTime(), -1 * $interval))
|
->setDatetime(DateTime::addSeconds(new \DateTime(), -1 * $interval))
|
||||||
->trigger();
|
->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function notifyDeleteTargets(Delete $queueForDeletes): void
|
|
||||||
{
|
|
||||||
$queueForDeletes
|
|
||||||
->setType(DELETE_TYPE_EXPIRED_TARGETS)
|
|
||||||
->trigger();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ class Builds extends Action
|
||||||
$this
|
$this
|
||||||
->desc('Builds worker')
|
->desc('Builds worker')
|
||||||
->inject('message')
|
->inject('message')
|
||||||
|
->inject('project')
|
||||||
->inject('dbForPlatform')
|
->inject('dbForPlatform')
|
||||||
->inject('queueForEvents')
|
->inject('queueForEvents')
|
||||||
->inject('queueForFunctions')
|
->inject('queueForFunctions')
|
||||||
|
|
@ -54,11 +55,12 @@ class Builds extends Action
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('deviceForFunctions')
|
->inject('deviceForFunctions')
|
||||||
->inject('log')
|
->inject('log')
|
||||||
->callback(fn ($message, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, Usage $usage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, Log $log) => $this->action($message, $dbForPlatform, $queueForEvents, $queueForFunctions, $usage, $cache, $dbForProject, $deviceForFunctions, $log));
|
->callback(fn ($message, Document $project, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, Usage $usage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, Log $log) => $this->action($message, $project, $dbForPlatform, $queueForEvents, $queueForFunctions, $usage, $cache, $dbForProject, $deviceForFunctions, $log));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Message $message
|
* @param Message $message
|
||||||
|
* @param Document $project
|
||||||
* @param Database $dbForPlatform
|
* @param Database $dbForPlatform
|
||||||
* @param Event $queueForEvents
|
* @param Event $queueForEvents
|
||||||
* @param Func $queueForFunctions
|
* @param Func $queueForFunctions
|
||||||
|
|
@ -70,7 +72,7 @@ class Builds extends Action
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Utopia\Database\Exception
|
* @throws \Utopia\Database\Exception
|
||||||
*/
|
*/
|
||||||
public function action(Message $message, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, Usage $queueForUsage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, Log $log): void
|
public function action(Message $message, Document $project, Database $dbForPlatform, Event $queueForEvents, Func $queueForFunctions, Usage $queueForUsage, Cache $cache, Database $dbForProject, Device $deviceForFunctions, Log $log): void
|
||||||
{
|
{
|
||||||
$payload = $message->getPayload() ?? [];
|
$payload = $message->getPayload() ?? [];
|
||||||
|
|
||||||
|
|
@ -79,7 +81,6 @@ class Builds extends Action
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $payload['type'] ?? '';
|
$type = $payload['type'] ?? '';
|
||||||
$project = new Document($payload['project'] ?? []);
|
|
||||||
$resource = new Document($payload['resource'] ?? []);
|
$resource = new Document($payload['resource'] ?? []);
|
||||||
$deployment = new Document($payload['deployment'] ?? []);
|
$deployment = new Document($payload['deployment'] ?? []);
|
||||||
$template = new Document($payload['template'] ?? []);
|
$template = new Document($payload['template'] ?? []);
|
||||||
|
|
|
||||||
|
|
@ -34,21 +34,23 @@ class Databases extends Action
|
||||||
$this
|
$this
|
||||||
->desc('Databases worker')
|
->desc('Databases worker')
|
||||||
->inject('message')
|
->inject('message')
|
||||||
|
->inject('project')
|
||||||
->inject('dbForPlatform')
|
->inject('dbForPlatform')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('log')
|
->inject('log')
|
||||||
->callback(fn (Message $message, Database $dbForPlatform, Database $dbForProject, Log $log) => $this->action($message, $dbForPlatform, $dbForProject, $log));
|
->callback(fn (Message $message, Document $project, Database $dbForPlatform, Database $dbForProject, Log $log) => $this->action($message, $project, $dbForPlatform, $dbForProject, $log));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Message $message
|
* @param Message $message
|
||||||
|
* @param Document $project
|
||||||
* @param Database $dbForPlatform
|
* @param Database $dbForPlatform
|
||||||
* @param Database $dbForProject
|
* @param Database $dbForProject
|
||||||
* @param Log $log
|
* @param Log $log
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function action(Message $message, Database $dbForPlatform, Database $dbForProject, Log $log): void
|
public function action(Message $message, Document $project, Database $dbForPlatform, Database $dbForProject, Log $log): void
|
||||||
{
|
{
|
||||||
$payload = $message->getPayload() ?? [];
|
$payload = $message->getPayload() ?? [];
|
||||||
|
|
||||||
|
|
@ -57,7 +59,6 @@ class Databases extends Action
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $payload['type'];
|
$type = $payload['type'];
|
||||||
$project = new Document($payload['project']);
|
|
||||||
$collection = new Document($payload['collection'] ?? []);
|
$collection = new Document($payload['collection'] ?? []);
|
||||||
$document = new Document($payload['document'] ?? []);
|
$document = new Document($payload['document'] ?? []);
|
||||||
$database = new Document($payload['database'] ?? []);
|
$database = new Document($payload['database'] ?? []);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class Deletes extends Action
|
||||||
$this
|
$this
|
||||||
->desc('Deletes worker')
|
->desc('Deletes worker')
|
||||||
->inject('message')
|
->inject('message')
|
||||||
|
->inject('project')
|
||||||
->inject('dbForPlatform')
|
->inject('dbForPlatform')
|
||||||
->inject('getProjectDB')
|
->inject('getProjectDB')
|
||||||
->inject('timelimit')
|
->inject('timelimit')
|
||||||
|
|
@ -55,8 +56,8 @@ class Deletes extends Action
|
||||||
->inject('auditRetention')
|
->inject('auditRetention')
|
||||||
->inject('log')
|
->inject('log')
|
||||||
->callback(
|
->callback(
|
||||||
fn ($message, $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log) =>
|
fn ($message, Document $project, Database $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log) =>
|
||||||
$this->action($message, $dbForPlatform, $getProjectDB, $timelimit, $deviceForFiles, $deviceForFunctions, $deviceForBuilds, $deviceForCache, $certificates, $executionRetention, $auditRetention, $log)
|
$this->action($message, $project, $dbForPlatform, $getProjectDB, $timelimit, $deviceForFiles, $deviceForFunctions, $deviceForBuilds, $deviceForCache, $certificates, $executionRetention, $auditRetention, $log)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +65,7 @@ class Deletes extends Action
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function action(Message $message, Database $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log): void
|
public function action(Message $message, Document $project, Database $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log): void
|
||||||
{
|
{
|
||||||
$payload = $message->getPayload() ?? [];
|
$payload = $message->getPayload() ?? [];
|
||||||
|
|
||||||
|
|
@ -78,7 +79,6 @@ class Deletes extends Action
|
||||||
$resource = $payload['resource'] ?? null;
|
$resource = $payload['resource'] ?? null;
|
||||||
$resourceType = $payload['resourceType'] ?? null;
|
$resourceType = $payload['resourceType'] ?? null;
|
||||||
$document = new Document($payload['document'] ?? []);
|
$document = new Document($payload['document'] ?? []);
|
||||||
$project = new Document($payload['project'] ?? []);
|
|
||||||
|
|
||||||
$log->addTag('projectId', $project->getId());
|
$log->addTag('projectId', $project->getId());
|
||||||
$log->addTag('type', $type);
|
$log->addTag('type', $type);
|
||||||
|
|
@ -153,6 +153,13 @@ class Deletes extends Action
|
||||||
case DELETE_TYPE_SESSION_TARGETS:
|
case DELETE_TYPE_SESSION_TARGETS:
|
||||||
$this->deleteSessionTargets($project, $getProjectDB, $document);
|
$this->deleteSessionTargets($project, $getProjectDB, $document);
|
||||||
break;
|
break;
|
||||||
|
case DELETE_TYPE_MAINTENANCE:
|
||||||
|
$this->deleteExpiredTargets($project, $getProjectDB);
|
||||||
|
$this->deleteExecutionLogs($project, $getProjectDB, $executionRetention);
|
||||||
|
$this->deleteAuditLogs($project, $getProjectDB, $auditRetention);
|
||||||
|
$this->deleteUsageStats($project, $getProjectDB, $hourlyUsageRetentionDatetime);
|
||||||
|
$this->deleteExpiredSessions($project, $getProjectDB);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \Exception('No delete operation for type: ' . \strval($type));
|
throw new \Exception('No delete operation for type: ' . \strval($type));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,15 +59,17 @@ class Messaging extends Action
|
||||||
$this
|
$this
|
||||||
->desc('Messaging worker')
|
->desc('Messaging worker')
|
||||||
->inject('message')
|
->inject('message')
|
||||||
|
->inject('project')
|
||||||
->inject('log')
|
->inject('log')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('deviceForFiles')
|
->inject('deviceForFiles')
|
||||||
->inject('queueForUsage')
|
->inject('queueForUsage')
|
||||||
->callback(fn (Message $message, Log $log, Database $dbForProject, Device $deviceForFiles, Usage $queueForUsage) => $this->action($message, $log, $dbForProject, $deviceForFiles, $queueForUsage));
|
->callback(fn (Message $message, Document $project, Log $log, Database $dbForProject, Device $deviceForFiles, Usage $queueForUsage) => $this->action($message, $project, $log, $dbForProject, $deviceForFiles, $queueForUsage));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Message $message
|
* @param Message $message
|
||||||
|
* @param Document $project
|
||||||
* @param Log $log
|
* @param Log $log
|
||||||
* @param Database $dbForProject
|
* @param Database $dbForProject
|
||||||
* @param Device $deviceForFiles
|
* @param Device $deviceForFiles
|
||||||
|
|
@ -77,6 +79,7 @@ class Messaging extends Action
|
||||||
*/
|
*/
|
||||||
public function action(
|
public function action(
|
||||||
Message $message,
|
Message $message,
|
||||||
|
Document $project,
|
||||||
Log $log,
|
Log $log,
|
||||||
Database $dbForProject,
|
Database $dbForProject,
|
||||||
Device $deviceForFiles,
|
Device $deviceForFiles,
|
||||||
|
|
@ -90,7 +93,6 @@ class Messaging extends Action
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $payload['type'] ?? '';
|
$type = $payload['type'] ?? '';
|
||||||
$project = new Document($payload['project'] ?? []);
|
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case MESSAGE_SEND_TYPE_INTERNAL:
|
case MESSAGE_SEND_TYPE_INTERNAL:
|
||||||
|
|
|
||||||
|
|
@ -51,16 +51,17 @@ class Migrations extends Action
|
||||||
$this
|
$this
|
||||||
->desc('Migrations worker')
|
->desc('Migrations worker')
|
||||||
->inject('message')
|
->inject('message')
|
||||||
|
->inject('project')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('dbForPlatform')
|
->inject('dbForPlatform')
|
||||||
->inject('logError')
|
->inject('logError')
|
||||||
->callback(fn (Message $message, Database $dbForProject, Database $dbForPlatform, callable $logError) => $this->action($message, $dbForProject, $dbForPlatform, $logError));
|
->callback(fn (Message $message, Document $project, Database $dbForProject, Database $dbForPlatform, callable $logError) => $this->action($message, $project, $dbForProject, $dbForPlatform, $logError));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function action(Message $message, Database $dbForProject, Database $dbForPlatform, callable $logError): void
|
public function action(Message $message, Document $project, Database $dbForProject, Database $dbForPlatform, callable $logError): void
|
||||||
{
|
{
|
||||||
$payload = $message->getPayload() ?? [];
|
$payload = $message->getPayload() ?? [];
|
||||||
|
|
||||||
|
|
@ -69,7 +70,6 @@ class Migrations extends Action
|
||||||
}
|
}
|
||||||
|
|
||||||
$events = $payload['events'] ?? [];
|
$events = $payload['events'] ?? [];
|
||||||
$project = new Document($payload['project'] ?? []);
|
|
||||||
$migration = new Document($payload['migration'] ?? []);
|
$migration = new Document($payload['migration'] ?? []);
|
||||||
|
|
||||||
if ($project->getId() === 'console') {
|
if ($project->getId() === 'console') {
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,11 @@ class Usage extends Action
|
||||||
$this
|
$this
|
||||||
->desc('Usage worker')
|
->desc('Usage worker')
|
||||||
->inject('message')
|
->inject('message')
|
||||||
|
->inject('project')
|
||||||
->inject('getProjectDB')
|
->inject('getProjectDB')
|
||||||
->inject('queueForUsageDump')
|
->inject('queueForUsageDump')
|
||||||
->callback(function (Message $message, callable $getProjectDB, UsageDump $queueForUsageDump) {
|
->callback(function (Message $message, Document $project, callable $getProjectDB, UsageDump $queueForUsageDump) {
|
||||||
$this->action($message, $getProjectDB, $queueForUsageDump);
|
$this->action($message, $project, $getProjectDB, $queueForUsageDump);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20');
|
$this->aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20');
|
||||||
|
|
@ -46,21 +47,20 @@ class Usage extends Action
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Message $message
|
* @param Message $message
|
||||||
|
* @param Document $project
|
||||||
* @param callable $getProjectDB
|
* @param callable $getProjectDB
|
||||||
* @param UsageDump $queueForUsageDump
|
* @param UsageDump $queueForUsageDump
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Utopia\Database\Exception
|
* @throws \Utopia\Database\Exception
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function action(Message $message, callable $getProjectDB, UsageDump $queueForUsageDump): void
|
public function action(Message $message, Document $project, callable $getProjectDB, UsageDump $queueForUsageDump): void
|
||||||
{
|
{
|
||||||
$payload = $message->getPayload() ?? [];
|
$payload = $message->getPayload() ?? [];
|
||||||
if (empty($payload)) {
|
if (empty($payload)) {
|
||||||
throw new Exception('Missing payload');
|
throw new Exception('Missing payload');
|
||||||
}
|
}
|
||||||
|
|
||||||
$document = $payload['project'] ?? [];
|
|
||||||
$project = new Document($document);
|
|
||||||
|
|
||||||
if (empty($project->getAttribute('database'))) {
|
if (empty($project->getAttribute('database'))) {
|
||||||
var_dump($payload);
|
var_dump($payload);
|
||||||
|
|
|
||||||
|
|
@ -59,26 +59,11 @@ class UsageDump extends Action
|
||||||
|
|
||||||
|
|
||||||
foreach ($payload['stats'] ?? [] as $stats) {
|
foreach ($payload['stats'] ?? [] as $stats) {
|
||||||
//$project = new Document($stats['project'] ?? []);
|
$project = new Document($stats['project'] ?? []);
|
||||||
|
|
||||||
/**
|
|
||||||
* Start temp bug fallback
|
|
||||||
*/
|
|
||||||
$document = $stats['project'] ?? [];
|
|
||||||
if (!empty($document['$uid'])) {
|
|
||||||
$document['$id'] = $document['$uid'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$project = new Document($document);
|
|
||||||
|
|
||||||
if (empty($project->getAttribute('database'))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End temp bug fallback
|
* End temp bug fallback
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$numberOfKeys = !empty($stats['keys']) ? count($stats['keys']) : 0;
|
$numberOfKeys = !empty($stats['keys']) ? count($stats['keys']) : 0;
|
||||||
$receivedAt = $stats['receivedAt'] ?? 'NONE';
|
$receivedAt = $stats['receivedAt'] ?? 'NONE';
|
||||||
if ($numberOfKeys === 0) {
|
if ($numberOfKeys === 0) {
|
||||||
|
|
|
||||||
|
|
@ -32,22 +32,24 @@ class Webhooks extends Action
|
||||||
$this
|
$this
|
||||||
->desc('Webhooks worker')
|
->desc('Webhooks worker')
|
||||||
->inject('message')
|
->inject('message')
|
||||||
|
->inject('project')
|
||||||
->inject('dbForPlatform')
|
->inject('dbForPlatform')
|
||||||
->inject('queueForMails')
|
->inject('queueForMails')
|
||||||
->inject('queueForUsage')
|
->inject('queueForUsage')
|
||||||
->inject('log')
|
->inject('log')
|
||||||
->callback(fn (Message $message, Database $dbForPlatform, Mail $queueForMails, Usage $queueForUsage, Log $log) => $this->action($message, $dbForPlatform, $queueForMails, $queueForUsage, $log));
|
->callback(fn (Message $message, Document $project, Database $dbForPlatform, Mail $queueForMails, Usage $queueForUsage, Log $log) => $this->action($message, $project, $dbForPlatform, $queueForMails, $queueForUsage, $log));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Message $message
|
* @param Message $message
|
||||||
|
* @param Document $project
|
||||||
* @param Database $dbForPlatform
|
* @param Database $dbForPlatform
|
||||||
* @param Mail $queueForMails
|
* @param Mail $queueForMails
|
||||||
* @param Log $log
|
* @param Log $log
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function action(Message $message, Database $dbForPlatform, Mail $queueForMails, Usage $queueForUsage, Log $log): void
|
public function action(Message $message, Document $project, Database $dbForPlatform, Mail $queueForMails, Usage $queueForUsage, Log $log): void
|
||||||
{
|
{
|
||||||
$this->errors = [];
|
$this->errors = [];
|
||||||
$payload = $message->getPayload() ?? [];
|
$payload = $message->getPayload() ?? [];
|
||||||
|
|
@ -60,8 +62,6 @@ class Webhooks extends Action
|
||||||
$webhookPayload = json_encode($payload['payload']);
|
$webhookPayload = json_encode($payload['payload']);
|
||||||
$user = new Document($payload['user'] ?? []);
|
$user = new Document($payload['user'] ?? []);
|
||||||
|
|
||||||
$project = new Document($payload['project']);
|
|
||||||
$project = $dbForPlatform->getDocument('projects', $project->getId());
|
|
||||||
$log->addTag('projectId', $project->getId());
|
$log->addTag('projectId', $project->getId());
|
||||||
|
|
||||||
foreach ($project->getAttribute('webhooks', []) as $webhook) {
|
foreach ($project->getAttribute('webhooks', []) as $webhook) {
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
|
|
||||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||||
$this->assertEquals('ready', $deployment['body']['status']);
|
$this->assertEquals('ready', $deployment['body']['status']);
|
||||||
}, 500000, 1000);
|
}, 50000, 1000);
|
||||||
|
|
||||||
$function = $this->getFunction($functionId);
|
$function = $this->getFunction($functionId);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue