redis-syncs

This commit is contained in:
shimon
2022-10-02 18:40:18 +03:00
parent 09830aecb3
commit 4a8befd110
11 changed files with 261 additions and 5391 deletions
+4 -1
View File
@@ -351,7 +351,10 @@ RUN chmod +x /usr/local/bin/doctor && \
chmod +x /usr/local/bin/worker-builds && \
chmod +x /usr/local/bin/worker-mails && \
chmod +x /usr/local/bin/worker-messaging && \
chmod +x /usr/local/bin/worker-webhooks
chmod +x /usr/local/bin/worker-webhooks && \
chmod +x /usr/local/bin/worker-syncs-out && \
chmod +x /usr/local/bin/worker-syncs-in
# Letsencrypt Permissions
RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/
+21 -2
View File
@@ -18,6 +18,7 @@ ini_set('display_startup_errors', 1);
ini_set('default_socket_timeout', -1);
error_reporting(E_ALL);
use Appwrite\Event\SyncOut;
use Appwrite\Extend\PDO;
use Ahc\Jwt\JWT;
use Ahc\Jwt\JWTException;
@@ -36,6 +37,7 @@ use Appwrite\Event\Delete;
use Appwrite\Event\Event;
use Appwrite\Event\Mail;
use Appwrite\Event\Phone;
use Appwrite\Event\SyncIn;
use Appwrite\Network\Validator\Email;
use Appwrite\Network\Validator\IP;
use Appwrite\Network\Validator\URL;
@@ -749,8 +751,7 @@ App::setResource('messaging', fn() => new Phone());
App::setResource('usage', function ($register) {
return new Stats($register->get('statsd'));
}, ['register']);
App::setResource('clients', function ($request, $console, $project) {
App::setResource('clients', function ($request, $console, $project) use ($register) {
$console->setAttribute('platforms', [ // Always allow current host
'$collection' => ID::custom('platforms'),
'name' => 'Current Host',
@@ -758,6 +759,24 @@ App::setResource('clients', function ($request, $console, $project) {
'hostname' => $request->getHostname(),
], Document::SET_TYPE_APPEND);
$register->set('syncOut', function () {
return new SyncOut();
});
cache::on(cache::EVENT_PURGE, function ($key) use ($register) {
$register
->get('syncOut')
->addKey($key)
->trigger();
});
cache::on(cache::EVENT_SAVE, function ($key) use ($register) {
$register
->get('syncOut')
->addKey($key)
->trigger();
});
/**
* Get All verified client URLs for both console and current projects
* + Filter for duplicated entries
+31
View File
@@ -0,0 +1,31 @@
<?php
use Appwrite\Resque\Worker;
use Utopia\CLI\Console;
require_once __DIR__ . '/../init.php';
Console::title('Syncs in V1 Worker');
Console::success(APP_NAME . ' syncs in worker v1 has started');
class SyncsInV1 extends Worker
{
protected array $errors = [];
public function getName(): string
{
return "syncs-in";
}
public function init(): void
{
}
public function run(): void
{
}
public function shutdown(): void
{
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
use Appwrite\Resque\Worker;
use Utopia\CLI\Console;
require_once __DIR__ . '/../init.php';
Console::title('Syncs out V1 Worker');
Console::success(APP_NAME . ' syncs out worker v1 has started');
class SyncsOutV1 extends Worker
{
protected array $errors = [];
public function getName(): string
{
return "syncs-out";
}
public function init(): void
{
}
public function run(): void
{
var_dump('run');
var_dump($this->args['key']);
}
public function shutdown(): void
{
}
}
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
if [ -z "$_APP_REDIS_USER" ] && [ -z "$_APP_REDIS_PASS" ]
then
REDIS_BACKEND="${_APP_REDIS_HOST}:${_APP_REDIS_PORT}"
else
REDIS_BACKEND="redis://${_APP_REDIS_USER}:${_APP_REDIS_PASS}@${_APP_REDIS_HOST}:${_APP_REDIS_PORT}"
fi
INTERVAL=0.1 QUEUE='v1-syncs-in' APP_INCLUDE='/usr/src/code/app/workers/syncsIn.php' php /usr/src/code/vendor/bin/resque -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
if [ -z "$_APP_REDIS_USER" ] && [ -z "$_APP_REDIS_PASS" ]
then
REDIS_BACKEND="${_APP_REDIS_HOST}:${_APP_REDIS_PORT}"
else
REDIS_BACKEND="redis://${_APP_REDIS_USER}:${_APP_REDIS_PASS}@${_APP_REDIS_HOST}:${_APP_REDIS_PORT}"
fi
INTERVAL=0.1 QUEUE='v1-syncs-out' APP_INCLUDE='/usr/src/code/app/workers/syncsOut.php' php /usr/src/code/vendor/bin/resque -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php
Generated
-5388
View File
File diff suppressed because it is too large Load Diff
+43
View File
@@ -107,6 +107,7 @@ services:
- ./public:/usr/src/code/public
- ./src:/usr/src/code/src
- ./dev:/usr/local/dev
- ./vendor/utopia-php/cache:/usr/src/code/vendor/utopia-php/cache
depends_on:
- mariadb
- redis
@@ -254,6 +255,48 @@ services:
- _APP_LOGGING_PROVIDER
- _APP_LOGGING_CONFIG
appwrite-worker-syncs-out:
entrypoint: worker-syncs-out
<<: *x-logging
container_name: appwrite-worker-syncs-out
build:
context: .
networks:
- appwrite
volumes:
- ./app:/usr/src/code/app
- ./src:/usr/src/code/src
- ./vendor/utopia-php/cache:/usr/src/code/vendor/utopia-php/cache
depends_on:
- redis
environment:
- _APP_ENV
- _APP_REDIS_HOST
- _APP_REDIS_PORT
- _APP_REDIS_USER
- _APP_REDIS_PASS
appwrite-worker-syncs-in:
entrypoint: worker-syncs-in
<<: *x-logging
container_name: appwrite-worker-syncs-in
build:
context: .
networks:
- appwrite
volumes:
- ./app:/usr/src/code/app
- ./src:/usr/src/code/src
- ./vendor/utopia-php/cache:/usr/src/code/vendor/utopia-php/cache
depends_on:
- redis
environment:
- _APP_ENV
- _APP_REDIS_HOST
- _APP_REDIS_PORT
- _APP_REDIS_USER
- _APP_REDIS_PASS
appwrite-worker-webhooks:
entrypoint: worker-webhooks
<<: *x-logging
+6
View File
@@ -35,6 +35,12 @@ class Event
public const MESSAGING_QUEUE_NAME = 'v1-messaging';
public const MESSAGING_CLASS_NAME = 'MessagingV1';
public const SYNCS_IN_QUEUE_NAME = 'v1-syncs-in';
public const SYNCS_IN_CLASS_NAME = 'SyncsInV1';
public const SYNCS_OUT_QUEUE_NAME = 'v1-syncs-out';
public const SYNCS_OUT_CLASS_NAME = 'SyncsOutV1';
protected string $queue = '';
protected string $class = '';
protected string $event = '';
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Appwrite\Event;
use Resque;
class SyncIn extends Event
{
protected string $key = '';
public function __construct()
{
parent::__construct(Event::SYNCS_IN_QUEUE_NAME, Event::SYNCS_IN_CLASS_NAME);
}
/**
* Sets cache key.
*
* @param string $key
* @return self
*/
public function addKey(string $key): self
{
$this->key = $key;
return $this;
}
/**
* Returns cache key.
*
* @return string
*/
public function getKey(): string
{
return $this->key;
}
/**
* Executes the event and sends it to the messaging worker.
*
* @return string|bool
* @throws \InvalidArgumentException
*/
public function trigger(): string|bool
{
return Resque::enqueue($this->queue, $this->class, [
'key' => $this->key,
]);
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Appwrite\Event;
use Resque;
class SyncOut extends Event
{
protected string $key = '';
public function __construct()
{
parent::__construct(Event::SYNCS_OUT_QUEUE_NAME, Event::SYNCS_OUT_CLASS_NAME);
}
/**
* Sets cache key.
*
* @param string $key
* @return self
*/
public function addKey(string $key): self
{
$this->key = $key;
return $this;
}
/**
* Returns cache key.
*
* @return string
*/
public function getKey(): string
{
return $this->key;
}
/**
* Executes the event and sends it to the messaging worker.
*
* @return string|bool
* @throws \InvalidArgumentException
*/
public function trigger(): string|bool
{
return Resque::enqueue($this->queue, $this->class, [
'key' => $this->key,
]);
}
}