QA bug fixing
This commit is contained in:
parent
43adf758bd
commit
fdbb5b9810
|
@ -5,7 +5,6 @@ use Appwrite\Event\Func;
|
||||||
use Appwrite\Messaging\Adapter\Realtime;
|
use Appwrite\Messaging\Adapter\Realtime;
|
||||||
use Appwrite\Resque\Worker;
|
use Appwrite\Resque\Worker;
|
||||||
use Appwrite\Utopia\Response\Model\Deployment;
|
use Appwrite\Utopia\Response\Model\Deployment;
|
||||||
use Cron\CronExpression;
|
|
||||||
use Executor\Executor;
|
use Executor\Executor;
|
||||||
use Appwrite\Usage\Stats;
|
use Appwrite\Usage\Stats;
|
||||||
use Utopia\Database\DateTime;
|
use Utopia\Database\DateTime;
|
||||||
|
@ -59,6 +58,8 @@ class BuildsV1 extends Worker
|
||||||
|
|
||||||
protected function buildDeployment(Document $project, Document $function, Document $deployment)
|
protected function buildDeployment(Document $project, Document $function, Document $deployment)
|
||||||
{
|
{
|
||||||
|
global $register;
|
||||||
|
|
||||||
$dbForProject = $this->getProjectDB($project);
|
$dbForProject = $this->getProjectDB($project);
|
||||||
|
|
||||||
$function = $dbForProject->getDocument('functions', $function->getId());
|
$function = $dbForProject->getDocument('functions', $function->getId());
|
||||||
|
@ -122,7 +123,6 @@ class BuildsV1 extends Worker
|
||||||
->trigger();
|
->trigger();
|
||||||
|
|
||||||
/** Trigger Functions */
|
/** Trigger Functions */
|
||||||
global $register;
|
|
||||||
$pools = $register->get('pools');
|
$pools = $register->get('pools');
|
||||||
$connection = $pools->get('queue')->pop();
|
$connection = $pools->get('queue')->pop();
|
||||||
$functions = new Func($connection->getResource());
|
$functions = new Func($connection->getResource());
|
||||||
|
@ -202,6 +202,7 @@ class BuildsV1 extends Worker
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update function schedule */
|
/** Update function schedule */
|
||||||
|
$dbForConsole = $this->getConsoleDB();
|
||||||
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
|
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
|
||||||
$schedule->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'));
|
$schedule->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'));
|
||||||
|
|
||||||
|
@ -240,7 +241,6 @@ class BuildsV1 extends Worker
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Update usage stats */
|
/** Update usage stats */
|
||||||
global $register;
|
|
||||||
if (App::getEnv('_APP_USAGE_STATS', 'enabled') === 'enabled') {
|
if (App::getEnv('_APP_USAGE_STATS', 'enabled') === 'enabled') {
|
||||||
$statsd = $register->get('statsd');
|
$statsd = $register->get('statsd');
|
||||||
$usage = new Stats($statsd);
|
$usage = new Stats($statsd);
|
||||||
|
|
|
@ -270,7 +270,6 @@ $server->job()
|
||||||
throw new Exception('Missing payload');
|
throw new Exception('Missing payload');
|
||||||
}
|
}
|
||||||
|
|
||||||
var_dump(json_encode($payload));
|
|
||||||
$type = $payload['type'] ?? '';
|
$type = $payload['type'] ?? '';
|
||||||
$events = $payload['events'] ?? [];
|
$events = $payload['events'] ?? [];
|
||||||
$data = $payload['data'] ?? '';
|
$data = $payload['data'] ?? '';
|
||||||
|
@ -284,8 +283,45 @@ $server->job()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Event execution.
|
* Handle Schedule and HTTP execution.
|
||||||
*/
|
*/
|
||||||
|
switch ($type) {
|
||||||
|
case 'http':
|
||||||
|
$jwt = $payload['jwt'] ?? '';
|
||||||
|
$execution = new Document($payload['execution'] ?? []);
|
||||||
|
$user = new Document($payload['user'] ?? []);
|
||||||
|
$execute(
|
||||||
|
project: $project,
|
||||||
|
function: $function,
|
||||||
|
dbForProject: $dbForProject,
|
||||||
|
queueForFunctions: $queueForFunctions,
|
||||||
|
trigger: $type,
|
||||||
|
executionId: $execution->getId(),
|
||||||
|
event: null,
|
||||||
|
eventData: null,
|
||||||
|
data: $data,
|
||||||
|
user: $user,
|
||||||
|
jwt: $jwt,
|
||||||
|
statsd: $statsd,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'schedule':
|
||||||
|
$execute(
|
||||||
|
project: $project,
|
||||||
|
function: $function,
|
||||||
|
dbForProject: $dbForProject,
|
||||||
|
queueForFunctions: $queueForFunctions,
|
||||||
|
trigger: $type,
|
||||||
|
executionId: null,
|
||||||
|
event: null,
|
||||||
|
eventData: null,
|
||||||
|
data: null,
|
||||||
|
user: null,
|
||||||
|
jwt: null,
|
||||||
|
statsd: $statsd,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'event':
|
||||||
if (!empty($events)) {
|
if (!empty($events)) {
|
||||||
$limit = 30;
|
$limit = 30;
|
||||||
$sum = 30;
|
$sum = 30;
|
||||||
|
@ -315,7 +351,7 @@ $server->job()
|
||||||
project: $project,
|
project: $project,
|
||||||
function: $function,
|
function: $function,
|
||||||
queueForFunctions: $queueForFunctions,
|
queueForFunctions: $queueForFunctions,
|
||||||
trigger: 'event',
|
trigger: $type,
|
||||||
event: $events[0],
|
event: $events[0],
|
||||||
eventData: $eventData,
|
eventData: $eventData,
|
||||||
user: $user,
|
user: $user,
|
||||||
|
@ -326,48 +362,7 @@ $server->job()
|
||||||
Console::success('Triggered function: ' . $events[0]);
|
Console::success('Triggered function: ' . $events[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle Schedule and HTTP execution.
|
|
||||||
*/
|
|
||||||
switch ($type) {
|
|
||||||
case 'http':
|
|
||||||
$jwt = $payload['jwt'] ?? '';
|
|
||||||
$execution = new Document($payload['execution'] ?? []);
|
|
||||||
$user = new Document($payload['user'] ?? []);
|
|
||||||
$execute(
|
|
||||||
project: $project,
|
|
||||||
function: $function,
|
|
||||||
dbForProject: $dbForProject,
|
|
||||||
queueForFunctions: $queueForFunctions,
|
|
||||||
trigger: 'http',
|
|
||||||
executionId: $execution->getId(),
|
|
||||||
event: null,
|
|
||||||
eventData: null,
|
|
||||||
data: $data,
|
|
||||||
user: $user,
|
|
||||||
jwt: $jwt,
|
|
||||||
statsd: $statsd,
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case 'schedule':
|
|
||||||
$execute(
|
|
||||||
project: $project,
|
|
||||||
function: $function,
|
|
||||||
dbForProject: $dbForProject,
|
|
||||||
queueForFunctions: $queueForFunctions,
|
|
||||||
trigger: 'http',
|
|
||||||
executionId: null,
|
|
||||||
event: null,
|
|
||||||
eventData: null,
|
|
||||||
data: null,
|
|
||||||
user: null,
|
|
||||||
jwt: null,
|
|
||||||
statsd: $statsd,
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -258,6 +258,7 @@ services:
|
||||||
- mariadb
|
- mariadb
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DB_HOST
|
- _APP_DB_HOST
|
||||||
- _APP_DB_PORT
|
- _APP_DB_PORT
|
||||||
|
@ -291,6 +292,7 @@ services:
|
||||||
- request-catcher
|
- request-catcher
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_SYSTEM_SECURITY_EMAIL_ADDRESS
|
- _APP_SYSTEM_SECURITY_EMAIL_ADDRESS
|
||||||
- _APP_REDIS_HOST
|
- _APP_REDIS_HOST
|
||||||
|
@ -321,6 +323,7 @@ services:
|
||||||
- ./src:/usr/src/code/src
|
- ./src:/usr/src/code/src
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DB_HOST
|
- _APP_DB_HOST
|
||||||
- _APP_DB_PORT
|
- _APP_DB_PORT
|
||||||
|
@ -376,6 +379,7 @@ services:
|
||||||
- mariadb
|
- mariadb
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DB_HOST
|
- _APP_DB_HOST
|
||||||
- _APP_DB_PORT
|
- _APP_DB_PORT
|
||||||
|
@ -408,6 +412,7 @@ services:
|
||||||
- mariadb
|
- mariadb
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_EXECUTOR_SECRET
|
- _APP_EXECUTOR_SECRET
|
||||||
- _APP_EXECUTOR_HOST
|
- _APP_EXECUTOR_HOST
|
||||||
|
@ -444,6 +449,7 @@ services:
|
||||||
- ./src:/usr/src/code/src
|
- ./src:/usr/src/code/src
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DOMAIN
|
- _APP_DOMAIN
|
||||||
- _APP_DOMAIN_TARGET
|
- _APP_DOMAIN_TARGET
|
||||||
|
@ -480,6 +486,7 @@ services:
|
||||||
- openruntimes-executor
|
- openruntimes-executor
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DB_HOST
|
- _APP_DB_HOST
|
||||||
- _APP_DB_PORT
|
- _APP_DB_PORT
|
||||||
|
@ -500,7 +507,6 @@ services:
|
||||||
- _APP_USAGE_STATS
|
- _APP_USAGE_STATS
|
||||||
- DOCKERHUB_PULL_USERNAME
|
- DOCKERHUB_PULL_USERNAME
|
||||||
- DOCKERHUB_PULL_PASSWORD
|
- DOCKERHUB_PULL_PASSWORD
|
||||||
- _APP_WORKER_PER_CORE
|
|
||||||
|
|
||||||
appwrite-worker-mails:
|
appwrite-worker-mails:
|
||||||
entrypoint: worker-mails
|
entrypoint: worker-mails
|
||||||
|
@ -518,6 +524,7 @@ services:
|
||||||
# - smtp
|
# - smtp
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_SYSTEM_EMAIL_NAME
|
- _APP_SYSTEM_EMAIL_NAME
|
||||||
- _APP_SYSTEM_EMAIL_ADDRESS
|
- _APP_SYSTEM_EMAIL_ADDRESS
|
||||||
|
@ -548,6 +555,7 @@ services:
|
||||||
- redis
|
- redis
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_REDIS_HOST
|
- _APP_REDIS_HOST
|
||||||
- _APP_REDIS_PORT
|
- _APP_REDIS_PORT
|
||||||
- _APP_REDIS_USER
|
- _APP_REDIS_USER
|
||||||
|
@ -572,6 +580,7 @@ services:
|
||||||
- redis
|
- redis
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_DOMAIN
|
- _APP_DOMAIN
|
||||||
- _APP_DOMAIN_TARGET
|
- _APP_DOMAIN_TARGET
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
|
@ -624,6 +633,7 @@ services:
|
||||||
- mariadb
|
- mariadb
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DB_HOST
|
- _APP_DB_HOST
|
||||||
- _APP_DB_PORT
|
- _APP_DB_PORT
|
||||||
|
@ -662,6 +672,7 @@ services:
|
||||||
- mariadb
|
- mariadb
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_OPENSSL_KEY_V1
|
- _APP_OPENSSL_KEY_V1
|
||||||
- _APP_DB_HOST
|
- _APP_DB_HOST
|
||||||
- _APP_DB_PORT
|
- _APP_DB_PORT
|
||||||
|
@ -697,6 +708,7 @@ services:
|
||||||
- redis
|
- redis
|
||||||
environment:
|
environment:
|
||||||
- _APP_ENV
|
- _APP_ENV
|
||||||
|
- _APP_WORKER_PER_CORE
|
||||||
- _APP_REDIS_HOST
|
- _APP_REDIS_HOST
|
||||||
- _APP_REDIS_PORT
|
- _APP_REDIS_PORT
|
||||||
- _APP_REDIS_USER
|
- _APP_REDIS_USER
|
||||||
|
|
|
@ -97,7 +97,7 @@ class Schedule extends Action
|
||||||
|
|
||||||
$pools->reclaim();
|
$pools->reclaim();
|
||||||
|
|
||||||
Console::success("{$total} functions where loaded in " . (microtime(true) - $loadStart) . " seconds");
|
Console::success("{$total} functions were loaded in " . (microtime(true) - $loadStart) . " seconds");
|
||||||
|
|
||||||
Console::success("Starting timers at " . DateTime::now());
|
Console::success("Starting timers at " . DateTime::now());
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class Schedule extends Action
|
||||||
|
|
||||||
$pools->reclaim();
|
$pools->reclaim();
|
||||||
|
|
||||||
Console::log("Sync tick: {$total} schedules where updates in " . ($timerEnd - $timerStart) . " seconds");
|
Console::log("Sync tick: {$total} schedules were updated in " . ($timerEnd - $timerStart) . " seconds");
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,11 +185,14 @@ class Schedule extends Action
|
||||||
|
|
||||||
$total++;
|
$total++;
|
||||||
|
|
||||||
$promiseStart = \microtime(true); // in seconds
|
$promiseStart = \time(); // in seconds
|
||||||
$executionStart = $nextDate->getTimestamp(); // in seconds
|
$executionStart = $nextDate->getTimestamp(); // in seconds
|
||||||
$executionSleep = $executionStart - $promiseStart; // Time to wait from now until execution needs to be queued
|
$executionSleep = $executionStart - $promiseStart; // Time to wait from now until execution needs to be queued
|
||||||
|
$delay = $executionSleep;
|
||||||
|
|
||||||
$delay = \ceil(\intval($executionSleep));
|
\var_dump($delay);
|
||||||
|
\var_dump(\time());
|
||||||
|
\var_dump('---');
|
||||||
|
|
||||||
if (!isset($delayedExecutions[$delay])) {
|
if (!isset($delayedExecutions[$delay])) {
|
||||||
$delayedExecutions[$delay] = [];
|
$delayedExecutions[$delay] = [];
|
||||||
|
@ -228,7 +231,7 @@ class Schedule extends Action
|
||||||
|
|
||||||
$timerEnd = \microtime(true);
|
$timerEnd = \microtime(true);
|
||||||
$lastEnqueueUpdate = $timerStart;
|
$lastEnqueueUpdate = $timerStart;
|
||||||
Console::log("Enqueue tick: {$total} executions where enqueued in " . ($timerEnd - $timerStart) . " seconds");
|
Console::log("Enqueue tick: {$total} executions were enqueued in " . ($timerEnd - $timerStart) . " seconds");
|
||||||
};
|
};
|
||||||
|
|
||||||
Timer::tick(self::FUNCTION_ENQUEUE_TIMER * 1000, fn() => $enqueueFunctions());
|
Timer::tick(self::FUNCTION_ENQUEUE_TIMER * 1000, fn() => $enqueueFunctions());
|
||||||
|
|
Loading…
Reference in a new issue