mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
minor fixes
This commit is contained in:
@@ -6,13 +6,11 @@ use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Request;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\App;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Queue\Client;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\Assoc;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\WhiteList;
|
||||
|
||||
App::init()
|
||||
->groups(['edge'])
|
||||
@@ -42,7 +40,13 @@ App::post('/v1/edge/sync')
|
||||
if (empty($keys)) {
|
||||
throw new Exception(Exception::KEY_NOT_FOUND);
|
||||
}
|
||||
|
||||
$originEdgeUrl = $request->getHeader('origin-edge-url');
|
||||
$time = DateTime::now();
|
||||
|
||||
var_dump('[' . $time . '] incoming request from:' . $originEdgeUrl);
|
||||
var_dump($keys);
|
||||
|
||||
foreach ($keys as $parts) {
|
||||
$key = json_decode($parts);
|
||||
$queueForEdgeSyncIn
|
||||
|
||||
+8
-7
@@ -12,7 +12,7 @@ use Utopia\CLI\Console;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Pools\Connection;
|
||||
use Utopia\Queue\Connection;
|
||||
use Utopia\Queue\Adapter\Swoole;
|
||||
use Utopia\Queue\Client;
|
||||
use Utopia\Queue\Message;
|
||||
@@ -21,6 +21,7 @@ use Utopia\Registry\Registry;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Logger\Logger;
|
||||
use Utopia\Pools\Group;
|
||||
use Utopia\Storage\Device;
|
||||
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||
|
||||
@@ -88,7 +89,7 @@ Server::setResource('queueForCertificates', function (Connection $queue) {
|
||||
return new Certificate($queue);
|
||||
}, ['queue']);
|
||||
|
||||
Server::setResource('queueForSyncOut', function (Connection $queue) {
|
||||
Server::setResource('queueForEdgeSyncOut', function (Connection $queue) {
|
||||
return new Client('v1-sync-out', $queue);
|
||||
}, ['queue']);
|
||||
|
||||
@@ -107,13 +108,13 @@ Server::setResource('pools', function ($register) {
|
||||
$pools = $register->get('pools');
|
||||
$connection = $pools->get('queue')->pop()->getResource();
|
||||
$workerNumber = swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6));
|
||||
$workerNumber =1;
|
||||
|
||||
if (empty(App::getEnv('QUEUE'))) {
|
||||
throw new Exception('Please configure "QUEUE" environemnt variable.');
|
||||
}
|
||||
|
||||
$adapter = new Swoole($connection, $workerNumber, App::getEnv('QUEUE'));
|
||||
$server = new Server($adapter);
|
||||
$server = new Server($adapter);
|
||||
|
||||
$server
|
||||
->shutdown()
|
||||
@@ -245,7 +246,7 @@ function getProjectDB(Document $project): Database
|
||||
* @param string $projectId of the project
|
||||
* @return Device
|
||||
*/
|
||||
function getFunctionsDevice($projectId): Device
|
||||
function getFunctionsDevice(string $projectId): Device
|
||||
{
|
||||
return getDevice(APP_STORAGE_FUNCTIONS . '/app-' . $projectId);
|
||||
}
|
||||
@@ -255,7 +256,7 @@ function getFunctionsDevice($projectId): Device
|
||||
* @param string $projectId of the project
|
||||
* @return Device
|
||||
*/
|
||||
function getFilesDevice($projectId): Device
|
||||
function getFilesDevice(string $projectId): Device
|
||||
{
|
||||
return getDevice(APP_STORAGE_UPLOADS . '/app-' . $projectId);
|
||||
}
|
||||
@@ -265,7 +266,7 @@ function getFilesDevice($projectId): Device
|
||||
* @param string $projectId of the project
|
||||
* @return Device
|
||||
*/
|
||||
function getBuildsDevice($projectId): Device
|
||||
function getBuildsDevice(string $projectId): Device
|
||||
{
|
||||
return getDevice(APP_STORAGE_BUILDS . '/app-' . $projectId);
|
||||
}
|
||||
|
||||
@@ -109,6 +109,18 @@ Server::setResource('execute', function () {
|
||||
$certificate->setAttribute('renewDate', getRenewDate($domain->get()));
|
||||
$certificate->setAttribute('attempts', 0);
|
||||
$certificate->setAttribute('issueDate', DateTime::now());
|
||||
|
||||
// Enqueue certificate for regional sync
|
||||
$filename = APP_STORAGE_CERTIFICATES . '/' . $domain . '.tar.gz';
|
||||
if (file_exists($filename)) {
|
||||
$queueForEdgeSyncOut->enqueue([
|
||||
'type' => 'certificate',
|
||||
'key' => [
|
||||
'domain' => $domain,
|
||||
'contents' => base64_encode(file_get_contents($filename)),
|
||||
]
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
// Set exception as log in certificate document
|
||||
$certificate->setAttribute('log', $e->getMessage());
|
||||
@@ -128,17 +140,6 @@ Server::setResource('execute', function () {
|
||||
|
||||
// Save all changes we made to certificate document into database
|
||||
saveCertificateDocument($domain->get(), $certificate, $dbForConsole);
|
||||
|
||||
$filename = APP_STORAGE_CERTIFICATES . '/' . $domain . '.tar.gz';
|
||||
if (file_exists($filename)) {
|
||||
$queueForEdgeSyncOut->enqueue([
|
||||
'type' => 'certificate',
|
||||
'key' => [
|
||||
'domain' => $domain,
|
||||
'contents' => base64_encode(file_get_contents($filename)),
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -426,6 +427,7 @@ $server->job()
|
||||
->inject('message')
|
||||
->inject('dbForConsole')
|
||||
->inject('execute')
|
||||
->inject('queueForEdgeSyncOut')
|
||||
->action(function ($message, $dbForConsole, $execute, Client $queueForEdgeSyncOut) use ($server) {
|
||||
$payload = $message->getPayload() ?? [];
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ function call(string $url, string $token, array $data): int
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Authorization: Bearer ' . $token,
|
||||
'Origin-edge-url: ' . App::getEnv('_APP_REGION'),
|
||||
'Content-type: multipart/form-data; boundary=' . $delimiter,
|
||||
'Content-Length: ' . strlen($payload)
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user